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;
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 | run the "CD \ Program Files \ mysql \ MySQL Server 5.0 \ bin" command to enter the bin folder | use "mysqldump-u username-P databasename> exportfilename" to export the database to the 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;", Press enter, check what database you want to restore. Create the database, enter "create database voice;", Press ENTER; switch to the database you just created, enter "use voice;", Press ENTER; import data, 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 and enter the password to go To the MySQL console "mysql>", which is restored in the same way as 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
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/quietprofound/archive/2008/09/19/2947197.aspx