MYSQL command line Import and Export Database details, mysql command line Import and Export

Source: Internet
Author: User
Tags localhost mysql import database mysql backup

MYSQL command line Import and Export Database details, mysql command line Import and Export

Mysql command line import database:

1. The. SQL file to be imported is moved to the binfile, which is convenient.
2. Step 1 of the above-mentioned export
3. Enter MySQL: mysql-u username-p
For example, the command line I entered is mysql-u root-p (enter the same password for MySQL)
4. Create the database you want to create in MySQL-Front. An empty database is used, for example, create a target database named "news ".
5. Enter the mysql> use target database name.
For example, the command line I entered is mysql> use news;
6. Import file: the file name imported from mysql> source;
For example, the command line I entered is mysql> source news. SQL;

MySQL backup and restoration are completed using mysqldump, mysql, and source commands.
1. MySQL backup and restoration under Win32
1.1 backup
Start Menu | run | cmd | use the "cd \ Program Files \ MySQL Server 5.0 \ bin" command to enter the bin folder | use "mysqldump-u username-p databasename> exportfilename" to export database to file, for example, mysqldump-u root-p voice> voice. SQL, and then enter the password to start exporting.

1.2 restore
Enter the MySQL Command Line Client, enter the password, go to "mysql>", enter the Command "show databases;", and press enter to see what database you want to restore, enter "create database voice;", Press ENTER; switch to the database you just created, enter "use voice;", Press ENTER; import data, and enter "source voice. SQL; ", press enter to start importing, and" mysql> "is displayed again. If no error is returned, the restoration is successful.

2. MySQL backup and restoration in Linux
2.1 backup
[Root @ localhost ~] # Cd/var/lib/mysql (go to the MySQL database directory and adjust the directory based on your MySQL installation)
[Root @ localhost mysql] # mysqldump-u root-p voice> voice. SQL. Enter the password.
2.2 restore
Method 1:
[Root @ localhost ~] # Mysql-u root-p press enter, enter the password, and go to the MySQL console "mysql>", and restore the password with 1.2.
Method 2:
[Root @ localhost ~] # Cd/var/lib/mysql (go to the MySQL database directory and adjust the directory based on your MySQL installation)
[Root @ localhost mysql] # mysql-u root-p voice <voice. SQL, enter the password.

MySQL command line to export the database:
1. Go to the bin folder under the MySQL Directory: directory from cd MySQL to the bin folder
For example, if the command line I entered is cd C: \ Program Files \ MySQL Server 4.1 \ bin
(Or directly add the directory to the path of the windows environment variable)
2. Export Database: mysqldump-u username-p Database Name> exported file name
For example, the command line I entered is mysqldump-u root-p news> news. SQL (after entering the command, you will be asked to enter the MySQL password)
(If you export a single table, enter the table name after the database name)

3. The file news. SQL is automatically generated under the binfile.


How does mysql Export and Import databases and tables?

MySQL command line to export the database:
1. Go to the bin folder under the MySQL Directory: directory from cd MySQL to the bin folder
For example, if the command line I entered is cd C: \ Program Files \ MySQL Server 4.1 \ bin
(Or directly add the directory to the path of the windows environment variable)

2. Export Database: mysqldump-u username-p Database Name> exported file name
For example, the command line I entered is mysqldump-u root-p news> news. SQL (after entering the command, you will be asked to enter the MySQL password)
(If you export a single table, enter the table name after the database name)

3. The file news. SQL is automatically generated under the binfile.
Command Line import database:

1. The. SQL file to be imported is moved to the binfile, which is convenient.
2. Step 1 of the above-mentioned export
3. Enter MySQL: mysql-u username-p
For example, the command line I entered is mysql-u root-p (enter the same password for MySQL)
4. Create the database you want to create in MySQL-Front. An empty database is used, for example, create a target database named "news ".
5. Enter the mysql> use target database name.
For example, the command line I entered is mysql> use news;
6. Import file: the file name imported from mysql> source;
For example, the command line I entered is mysql> source news. SQL;

Do not copy the exported Mysql database.

Windows
1. Start-run (or press the windouws logo + r), Enter cmd, press enter, and the command line appears.
2. If you have not started the mysql service, enter net start mysql. Otherwise, skip this step.
3. Enter d:. Set the current directory to d to facilitate searching for the generated SQL file.
4. Enter the following command to export the entire database (note that the database name is yours ),
Press enter and enter the password to find the dbname. SQL file on drive D.
Mysqldump-u root-p Database Name> dbname. SQL
To export a table, run the following command:
Mysqldump-u root-p database name Table Name> dbname. SQL
5. During the import process, go to the mysql Database Console, such as mysql-u root-p.
Mysql> use Database
Then run the source command. The following parameter is the script file (for example,. SQL used here)
Mysql> source d: \ dbname. SQL
If you are prompted that the file cannot be found, you can drag the file directly into the command line window with the mouse after entering the sourw.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.