1. MySQL exports different types of table structures
1.1 Export structure does not export data
mysqldump -h 主机地址 -u root -p 密码 -d 数据库名 > xxx.sql # 加 -d 参数
If you find that the data will still be exported after adding -d
the parameter , you can -d
replace the parameter with--no-data
1.2 Exporting data does not export structure
mysqldump -h 主机地址 -u root -p 密码 -t 数据库名 > xxx.sql
1.3 Export data and table structure
mysqldump -h 主机地址 -u root -p 密码 数据库名 > xxx.sql # 不加 -d 参数
1.4 Export the structure of a specific table
Multiple tables (test1, test2, test3) structure and table data are separated by spaces
mysqldump -h 主机地址 -u root -p 密码 -B 数据库名 --table 表1,表2 > xxx.sql
1.5 May report an error
error 1
mysqldump: Got error: 1105: [parser:1149]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use when using LOCK TABLES
The solution is to add --skip-lock-tables
the parameter
error 2
Unknown table 'column_statistics' in information_schema (1109)
The solution is to add --column-statistics=0
parameters
2. Execute the .sql file and import data
2.1 Solution 1: Use the source command after logging in to mysql
use my_test_db # 进入某个数据库
source xxx/xx/xx.sql
2.2 Solution 2: Use the mysql command directly
The shell directly enters the following command
mysql -h 主机地址 -u root -p my_test_db < xxx/xx/xx.sql
3. Back up the database
mysqldump 数据库名 >数据库备份名
mysqldump -A -u用户名 -p密码 数据库名>数据库备份名
mysqldump -d -A --add-drop-table -uroot -p >xxx.sql
4. Prompt
If Baidu or Google can't find the solution, why not ask chatgpt directly, maybe it will have a solution.
5, Reference:
Mysql batch export table structure (data)
Mysql mysqldump only exports the table structure or only the data export method
mysqldump export error column_statistics
Mysql uses commands to execute sql files
Mysql database import sql file Mysql import and export method of .sql file
MySQL--mysqldump command detailed explanation (mysqldump command complete set)