Mysqldump Export Command Base usage
The code is as follows |
Copy Code |
Mysqldump-u username-P [--opt] DATABASENAME [Table] > Export SQL file name |
The default mysqldump exported SQL file contains not only the exported data, but also the structure information of all the data tables in the exported database
1. Export the entire database
Mysqldump-u user name-p database name > exported file name
The code is as follows |
Copy Code |
C:Program filesmysqlmysql Server 5.1bin>mysqldump-u root-p--opt MySQL >d:phpwebsqlbackupmysql.sql Enter Password: Hu Jintao |
2. Export a table
Mysqldump-u user name-P database name Table name > exported file name
The code is as follows |
Copy Code |
C:Program filesmysqlmysql Server 5.1bin>mysqldump-u root-p--opt mysql user >d:phpwebsqlbackupmysql_user.sql Enter Password: Hu Jintao |
3. Export a database structure
The code is as follows |
Copy Code |
Mysqldump-u wcnc-p-d–add-drop-table SMGP_APPS_WCNC >d:wcnc_db.sql |
-D No data –add-drop-table add a drop table before each CREATE statement
4. Import Database
Common source Commands
Enter the MySQL database console,
such as Mysql-u root-p
The code is as follows |
Copy Code |
Mysql>use Database |
Then use the source command, followed by the script file (such as the. SQL used here)
The code is as follows |
Copy Code |
Mysql>source D:linuxzg.sql |
more mysqldump command Parameters
In addition, SQL files exported using mysqldump are saved in the bin directory by default if they are not with an absolute path.
–opt: This mysqldump command parameter is optional, if this option is used to activate the quick,add-drop-table,add-locks,extended-insert,lock-tables parameter of the mysqldump command, That is, you do not need to append these parameters when using mysqldump to export MySQL database information through the –opt parameter.
–quick: On behalf of ignoring buffered output, the mysqldump command exports data directly to the specified SQL file.
–add-drop-table: As the name suggests, is to add drop-table IF exists statement before each create Tabel command to prevent the duplicate of the data table.
–add-locks: means locking and unlocking specific data tables before and after the insert data, you can open mysqldump exported SQL files, and the lock tables and unlock tables appear before the insert.
–extended-insert (-E): This parameter indicates that multiple rows can be inserted.