mysqldump 工具使用

297 阅读1分钟

目的

导出生产环境mysql数据到开发环境

工具

mysqldump

工具介绍

# game 是库名

# 完整导出一个库
# 包括建库语句、表结构、数据
mysqldump -uroot -proot --host=127.0.0.1 --port=3306 --databases game > test.sql

# 只导出表结构
mysqldump -uroot -proot --host=127.0.0.1 --port=3306 -d game > test.sql

# 只导出数据
mysqldump -uroot -proot --host=127.0.0.1 --port=3306 -t game > test.sql

# 导出一个数据库中多个表的数据和结构
mysqldump -uroot -proot --host=127.0.0.1 game --tables articles users > test.sql
mysqldump -uroot -proot --host=127.0.0.1 game articles users > test.sql

# 恢复导出数据
mysql -u username -proot databse < backup.sql

TIPS

出现错误信息:mysqldump Unknown table 'COLUMN_STATISTICS' 
添加以下参数:
--column-statistics=0