LB Hosting

Knowledgebase

How can I import and export a MySQL Database from the command line

Problem:


How can I import and export a MySQL Database from the command line

Solution:


MySQL Tutorial - Import or Export A Database

This tutorial section deals with mysqldump which is a tool to import and export MySQL databases. (this is all done via command line , you will need to ssh into your account)

It can be used to take backup a database or to transfer information from one server to another server.

1. Export A MySQL Database

This example shows you how to export a database. It is very good for taking backup of database again and again.

1. mysqldump -u username -p database_name > FILE.sql
2. Press Enter
3. You will be prompted for a password
4. Type in the password for the username and press Enter.


Replace username, password and database_name with your MySQL username, password and database name.

File FILE.sql now holds a backup of your database, download it to your computer.

2. Import A MySQL Database

Here If you want to import a database, then use data from backup or to import from another MYSQL Server.

Start by uploading the FILE.sql file to the server where you will be running this command.

1. mysql -u username -p database_name < FILE.sql
2. Press Enter
3. You will be prompted for a password
4. Type in the password for the username and press Enter.


This powerful, easy to use command has many uses. Let's say you wanted to switch web hosting providers.

Simply export your data on the old provider's server and import it on your account with the new host.

Keywords: import export MySQL Database command ssh



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read

Language: