UnixServerAdmin

Server Administration & Management

How to Import-Export MySQL database from shell

To export a database run

# mysqldump datbasename > databasename.sql

This will export the database to databasename.sql

To import a database from an sql dump file run

# mysql databasename < dumpsqlfilename.sql

This will import the sql file into the database. Once imported you should check to make sure it was correctly imported to do this run

mysql databasename
show tables;

If the you do not see any tables listed then the sql file likely has a USE statement at the top. Edit the sql file with a text editor and comment out the line “USE databasename”. Once commented out attempt to import the data and check the tablesl.

Advertisements

March 22, 2011 Posted by | MySQL, Unix/Linux | , , | 1 Comment