MySQL Tips

Import SQL via Command Line

mysql -u root -p database_name < file.sql

Export SQL via Command Line

mysqldump -u root -p database_name > database.sql

Import .sql.gz file via Command Line

gunzip < production.sql.gz | mysql -h hosturl -u username -p db_name

Import sql.gz file via Command Line with progress bar

sudo apt-get install pv
pv mydump.sql.gz | gunzip | mysql -u root -p

Find most common value in table

SELECT column, COUNT(*) AS magnitude 
FROM table 
GROUP BY column 
ORDER BY magnitude DESC
LIMIT 1

Last updated