Creating a MySQL dump file of your database can be fairly straightforward, but, if you aren't careful, you could corrupt the character set in your backup file.
I used to created a database dump using a command like the following:
mysqldump -u nathan -p database1 > database1.backup.sql
The above command is very straightforward in that it generates a dump file using default options and redirects the output to a file instead of to standard output.
However, I want all my data to maintain a UTF-8 character set. To do this I need to use 2 options:
--default-character-set=utf8: This insures UTF8 is used for each field
--result-file=file.sql: This option prevents the dump data from passing the through the Operating System which likely does not use UTF8. Instead it passes the dump data directly to the file specified.
Using these new options your dump command would look something like this:
mysqldump -u nathan -p --default-character-set=utf8 --result-file=database1.backup.sql database1
If you are like me and are constantly creating MySQL dumps, you might want to consider creating a simple shell script like the one I use below.
#!/bin/bash db_user="root" db_pass="password" mysqldump -u $db_user -p $db_pass --single-transaction --default-character-set=utf8 --result-file=$1.$(date -I).sql $1
The script just takes a single argument, the database name, and generates a datestamped dump file of it in the current directory.
Importing a dump safely
Do not do this, since it might screw up encoding:
mysql -u username -p database < dump_file # this is bad
Better do:
mysql -uroot -p --default-character-set=utf8 database mysql> SOURCE utf8.dump
相关推荐
mysqldump.exe 5.7工具,可以用来导出、导入mysql数据
在低版本备份高版本的时候会报错。可以尝试直接用高版本的mysqldump备份。但是的一个exe文件。
-bash: mysqldump: command not found问题解决
mysqldump
windows版本mysqldump 5.7.24版本 无需安装mysql直接cmd使用 切换到文件存放目录 直接使用命令即可 mysqldump -uroot -p databasename >data.sql
windows mysqldump 5.7.35
mysqldump 参数大全
mysqldump备份.sh
mysqldump 导入 导出 备份 还原 也是详解
已知mysql高版本(8.0及以上)自带的mysqldump对低版本的数据库具有兼容性问题,这里为高版本用户提供一个低版本的mysqldump.exe,使用方法:直接在本工具根目录使用cmd+参数进行数据库备份。 可以放入/mysql/bin,...
总结关于 mysqldump 多张表筛选备份的使用方法
mysqldump备份mysql数据库.docx
包里面的文件:mysql、mysqldump 两个命令 mysqldump使用方法:可直接使用,备份数据库 使用方法:mysqldump --opt -u用户名 -p密码 -hIP地址 -P数据库端口 要备份的库 > 导入指定的sql里 示例:mysqldump --opt -u...
详解 linux mysqldump 导出数据库、数据、表结构 导出完整的数据库备份: mysqldump -h127.0.0.1 -P3306 -uroot -ppassword --add-locks -q dbname > dbname.sql 说明:–add-locks:导出过程中锁定表,完成后回解锁...
mysqldump-5.6.21的导出工具,低版本的工具不能导出高版本的表结构和数据。
mysqldump 指导你使用怎么使用导入导出功能
生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库 一个合格的运维工程师或者dba工程师,如果有从事数据库方面的话,首先需要做的就是备份,如果没有备份,出现问题的话,你的业务就会出问题,你的工作...
利用Zabbix监控mysqldump定时备份.docx