原创作品,允许转载,转载时请务必以超链接形式标明文章 、作者信息和本声明。否则将追究法律责任。
1.mysqldump
mysqldump -u username -p databasename > backupfilesname2.查看备份前的数据库mysql -u root -p'oldboy123' -e "use dbname;show tables;select * from student;"3.备份数据库(该命令没有建库的命令,会将原先数据覆盖)mysqldump -u root -pdb123' oldboy > /opt/mysql_bak.sql4.检查备份结果egrep -v "#|\*|--|^$" /opt/mysql_bak.sql5.还原数据库mysql -u root -p'oldboy123' dbname < /opt/mysql_bak.sql6.解决mysqldump导出数据乱码问题:mysql -u root -p'db123' -e "show variables like '%character%'"7.查看Mysql源码包的安装路径信息ps -ef | grep mysql8.修改环境变量,使mysqldump直接在shell中执行vi /etc/profilesource /etc/profile9.查看Mysql字符集mysql -u root -p -e "show variables like '%character%'"10.指定字符集导出数据库mysqldump -uroot -p'db123' --default-character-set=latin1 dbnamey > /opt/mysql_bak.sqlegrep -v "#|\*|--|^$" /opt/mysql_bak.sql11.查看已创建数据库的字符集mysql -uroot -pshow create database water_station\G12.mysqldump -B参数(恢复时不要数据库存在)
mysqldump -uroot -p'db123' -B dbname > /opt/mysql_bak_B.sqlmysql -uroot -p'db123' < /opt/mysql_bak_B.sql13.文件对比
diff mysql_bak.sql mysql_bak_B.sql14.优化备份文件大小减少输入注释(Debug调试)
mysqldump -uroot -p'db123' --compact -B dbname> /opt/mysql_bak_B_compact.sqlless /opt/mysql_bak_B_compact.sql15.指定压缩参数来备份数据库gzip
mysqldump -uroot -p'db123' -B dbname | gzip > /opt/mysql_bak_B.sql.gzgunzip /opt/mysql_bak_B.sql.gz16.备份指定的多个数据库
mysqldump -uroot -p'db123' -B dbname dbname_gbk | gzip > /opt/mysql_mul.sql.gz 17.mysql -uroot -p -e "show databases;"| grep -Evi "database|infor|perfor"|sed 's#^#mysqldup -uroot -p'123456' -B #g'本文出自 “” 博客,请务必保留此出处