MySQL command line import, export, backup, restore database

MySQL command line to export the database:
1. Enter the bin folder under the MySQL directory: cd MySQL to the bin folder directory
as I entered the command line: cd C:\Program Files\MySQL\MySQL Server 4.1\bin
(or directly Add this directory to the Windows environment variable path)


2. Export the database: mysqldump -u username -p database name > the exported file name is 
like the command line I entered: mysqldump -u root -p news > news.sql (you will enter the password to enter MySQL after entering it)
( If you export a single table, enter the table name after the database name)

3. You will see that the file news.sql is automatically generated to the bin file under the  
command line to import the database:


1. Move the .sql file to be imported to the bin file. This path is more convenient
. 2. Same as the first export step
3. Enter MySQL: mysql -u username -p
as the command line I entered: mysql -u root -p (you will enter the MySQL password after entering the same)
4. Create a new database in MySQL-Front, which is an empty database. For example, create a new target database named news
5. Enter: mysql> The use target database name is
like the command line I entered: mysql>use news;
6, the import file: mysql>source The imported file name; 
such as the command line I entered: mysql>source news.sql; 

MySQL backup and restore are done using mysqldump, mysql and source commands. 
1. Backup and restore of MySQL under Win32 
1.1 Backup 
Start Menu | Run | cmd | Use "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 a file, such as mysqldump -u root -p voice>voice.sql, and then enter the password to start the export. 
  
1.2 Restore 
Enter the MySQL Command Line Client, enter the password, enter "mysql>", enter the command "show databases;", press Enter, and see what databases are there; create the database you want to restore, enter "create database voice;", Enter; switch to the newly created database, enter "use voice;", enter; import data, enter "source voice.sql;", enter, start importing, "mysql>" appears again and there is no error prompting success. 
  
2. Backup and restore of MySQL under Linux 
2.1 Backup 
[root@localhost ~]# cd /var/lib/mysql (enter the MySQL library directory and adjust the directory according to your own MySQL installation) 
[root@localhost mysql]# mysqldump -u root -p voice>voice.sql, enter the password.
2.2 Reduction
method one:
[root@localhost ~]# mysql -u root -p Enter, enter the password, enter the MySQL console "mysql>", and restore the same as 1.2.
Method 2:
[root@localhost ~]# cd /var/lib/mysql (Enter the MySQL library directory and adjust the directory according to your own MySQL installation) 
[root@localhost mysql]# mysql -u root -p voice<voice .sql, enter the password.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326239814&siteId=291194637