Search This Blog

Thursday, May 24, 2018

howto import and export data from mysql using the command line interface

Found myself in need to quickly transfer data between mysql databases in different computers. 
searched the web and found a nice guide. As I don't usually work with mysql, and whenever mysql issues arise, they are usually in relation to time-stress issues, I thought summarizing the data, just in case, might be a good idea:
exporting from the source computer:
mysqldump -u [dbuser] -p [database-name] > /tmp/[dumpfilename]

Pay attention: you do not provide the password in the command. it will be asked for (assuming the user has a password) when the program runs. 

Now transfer the file to the target computer. 
and there - 
enter into mysql and create the database. 
(once inside  the mysql command interface, just issue  create database [database-name] 
then return to the command line  and issue:
mysql -u [dbuser] -p [database-name] < /tmp/[dumpfilename]
Once again - Pay attention: you do not provide the password in the command. it will be asked for (assuming the user has a password) when the program runs. 

a remark:
what you get is a lovely text file, with mysql commands that shall create the database content (tables and actual content). I did not export/import a very sophisticated db, so I still do not know the limitations of this transport method.  As usual, and as is especially important to remember the quick-and-dirty solutions, use the method with care, and be willing to spend time learning more and tackling surprising aspects that one might not expect, but that usually arise in database export/import processes. But it did work for me in a very simple db transfer. 


No comments:

Post a Comment