Dec 1, 2008

Quick Tip: Export & Import MySQL files

This is a tip left over from my previous blog. In case that blog shuts down (hosting issues..) I thought it would be handy to post on this one. Hey, if you're a newbie to the MySQL command line then you may need all the help you can get!


Step 1: Export a MySQL database (also known as dumping a mysql db)
mysqldump --databases --result-file=12012008_mydatabase.sql mydatabase -u mysqluser -p

or

mysqldump -u root -p mydatabase > 12012008_mydatabase.sql

Step 2a: Create a db in MySQL to host the import:
mysql -u mysqluser -p


Then, once you enter the password for the mysqluser:
create database mydatabase;
exit;


Step 2b: Import the data into the database:
mysql -u mysqluser -p mydatabase < 12012008_mydatabase.sql
This can be useful especially if you need to take backups. Remember that phpmyadmin has some limits for file imports and your webserver may timeout on exports so it's always good to have some command line tools in your arsenal.

No comments:

Post a Comment