Quantcast
Channel: Fatih Karatana, Software Architect & Business Coach » Tag » MySQL
Viewing all articles
Browse latest Browse all 2

MySQL Export and Import via Command

$
0
0

MySQLHey guys,

I’m writing this article because so many times MySQL developers may need to use command prompt to manage their MySQLdatabases so far we need some commands for important task to do via SSH.

Even better if you can use phpMyAdmin of course but there may not available to find out a control panel on personally hosted MySQL database and you should connect via SSH to manage database. The one of the main needs is exporting and importing databases between seperate databases.

There is an easy way to do this right away and it is called mysqldump

First we’ll see how-to export a MySQL database no more detail just code (:

#mysqldump -u [username] -p [password] [database_name] > FILE.sql

Just write the code above by replacing username, password and database_name keys and also remove bracket then File FILE.sql will hold a backup of your database, download it to your computer. You can do it by FTP or scopy command.

Here is now how to import a MySQL database:

I assume that you already uploaded the FILE.sql on to the server and run the command below to import database in its file location:

#mysql -u [username] -p [password] [database_name] < FILE.sql

Replace the same information in the code such as you’ve done when you’re importing.

The commands I’ve mentioned above are powerful, easy to use command has many uses. And let’s see the older host providers commands.

We can dump out our database which is currently running on an old server by using mysqldump

To dump our database we should use a Telnet or SSH client and then run the comand below:

mysqldump -u database_user -p database_name > FILE.sql

Again just do the same replacing like above.

After we type the command we’ll be prompted for your old host’s MySQL password, which will not echo back at we as we type. After we provide the correct password, the file will be on our host in the current directory called FILE.sql containing the whole database.

Doing all these steps is not hard but takes time so if you are available to do this over phpMyAdmin just use Export/Import links on the main navigation. No more effort (:


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images