Importing and Exporting MySQL Database via Cli


Reminders:

------------

This can be can done not only in Linux but also in Windows via cmd and via SSH.
Exporting MySQL Database and it's table:
----------------------------------------

Syntax:

mysqldump -p -u [database_username] [database_name] > tables.sql

Example:
---------

mysqldump -p -u rootUser mysitedb > dbmysite.sql

Notes:
---------
  • Do not use flag -p if you don't have a password
  • If you don't have password, please create one.
  • After you run the command, it will ask for password
  • The output tables.sql will be in your working current directory.
  • To know what folder you are after you run the command, in Linux simply type pwd and enter.

Importing MySQL Database and it's table:
----------------------------------------

Syntax:

mysql -p -u [database_username] [database_name] < tables.sql

Example:
---------

mysql -p -u rootUser mysitedb < tbmysite.sql


Common Questions:
---------------------

Q: It doesn't work at all, I got errors
A: Before pasting the error, Please Make sure you have MySQL installed, check the special characters in your .SQL file such as "" vs ‘ ’  vs“ ” and password is correct.


Q: It works but I can't find the file
A: Just locate what folder you are currently in when you perform
command.


Q: Memory limitation; Cannot upload huge file size
A: Check your server or mysql max_file_size_upload just like 
in PHP.ini

Import / Export MySQL via Command Line

Posted on

Wednesday, September 25, 2013

Category

,

,

,

,

Leave a Reply

I love comments hopefully you can put one.