Category Archive:

How to import a delimited file with mysql

0

Using Mac OS X on the command line, log into mysql and select your database. Then run the following for a tab delimited file located on your desktop:

load data LOCAL infile ‘/Users/YOURNAME/Desktop/standards.txt’ into table TABLE_NAME fields terminated by “\t” lines terminated by “\r”

Posted in: Development, MySQL

Continue Reading

How to download and import a large mysql database locally

0

Download the remote file
scp my_username_on_remote_server@remote_server_ip_address:fullPathToFileOnRemoteServer pathToPutFileOnLocalMachine

If the file was zipped, then we’ll need to unzip it locally
gunzip -f pathToFileOnLocalMachine

Then load the data into the database
mysql -u root -p -h localhost databaseName < pathToUnzippedFileOnLocalMachine

Posted in: MySQL

Continue Reading

How to stop a mysql process

0

Get into an infinite loop or query that’s taking longer than your patience will allow? Using mysql’s “kill” command will be helpful in this case. First log into mysql and view the process list “select * from information_schema.processlist;” . View the list of processes and identify the process id number of the process you want to stop, then run “kill (process id);”. Be careful when stopping queries other than selects because you may run into some data corruption.

Posted in: MySQL

Continue Reading

Mixing of GROUP columns (MIN(),MAX(),COUNT(),…) with no GROUP columns is illegal if there is no GROUP BY clause

0

I wrote a query similar to the one below that worked in my development environment using MySQL, but failed on other environments.
SELECT customer_id, sum(rating) FROM customer

The reason it failed is because for proper SQL, columns not included in an aggregate function like “SUM” need to be specified in the group by clause. However, more recent versions of MySQL will handle this for you automatically. If the version of MySQL differs between your environments as mine did, you might run into an issue.

The solution is to write the sql query properly as below and edit your MySQL’s my.cnf file by adding the line sql_mode = ONLY_FULL_GROUP_BY .
SELECT customer_id, sum(rating) FROM customer group by customer_id

Posted in: MySQL

Continue Reading

Spreadsheet listing of all cities in the world

0

I was in need of a source containing all cities in the united states for my new personal web project. I found this source http://www.populardata.com/zipcode_database.html , but quickly found that it was missing many entries (it has 43,000 cities). However, after more searching I came across this source http://www.maxmind.com/app/worldcities that has call cities in the world listed by country and state. They have 142,000 cities listed for the United States and is much more complete.

Posted in: Development, MySQL, PHP

Continue Reading