In normal mysql applications, there are always many ways to import and export data. This article mainly introduces how to use the mysqlmysqldump command to import and export data. it is helpful to everyone.
In normal mysql applications, there are always many ways to import and export data. This article mainly introduces how to use the mysqlmysqldump command to import and export data. it is helpful to everyone.
The mysqldump command carries the -- where/-w parameter, which is used to set the data export conditions. The usage is basically the same as that in the SQL query command, we can export the data you need from the database.
1. the command format is as follows:
Mysqldump-u user name-p password database name table name -- where = "filter condition"> Export file path
Example:
Export data with an id greater than 100 from the test_data table of the test database to the/tmp/test. SQL file.
The code is as follows: |
|
Mysqldump-uroot-p123456 test test_data -- where = "id> 100">/tmp/test. SQL |
2. export the entire database
Mysqldump-u username-p database name> exported file name
The code is as follows: |
|
Mysqldump-u wcnc-p smgp_rj_wcnc> wcnc. SQL |
3. export a database structure
The code is as follows: |
|
Mysqldump-u wcnc-p-d -- add-drop-table smgp_apps_wcnc> d: wcnc_db. SQL -D no data -- add-drop-table adds a drop table before each create statement. |
Mysqldump conditions
Mysqldump-u username-p password-h host Database a-w "SQL condition"-lock-all-tables> path
The code is as follows: |
|
1 mysqldump-hhostname-uusername-p dbname tbname> xxxx. SQL ** Export the database table content based on the specified conditions. (-W option-where) 1 mysqldump-hhostname-uusername-p dbname tbname-W' id> = 1 and id <= 10000 '-- skip-lock-tables> xxxx. SQL Or 1 mysqldump-hhostname-uusername-p dbname tbname -- where = 'unit _ id> = 1 and unit_id <= 10000 '> ~ /Xxxx. SQL |