MySQL Backup restore

Source: Internet
Author: User
Tags mysql backup egrep

1.mysqldump
Mysqldump-u username-p databasename > Backupfilesname
2. View the database before the backup
Mysql-u root-p ' oldboy123 '-e "use dbname;show tables;select * from student;"
3. Back up the database (this command does not have a command to build a library, overwriting the original data)
Mysqldump-u root-pdb123 ' Oldboy >/opt/mysql_bak.sql
4. Check the backup results
Egrep-v "#|\*|--|^$"/opt/mysql_bak.sql
5. Restore the database
Mysql-u root-p ' oldboy123 ' dbname </opt/mysql_bak.sql
6. Solve mysqldump Export Data garbled problem:
Mysql-u root-p ' db123 '-e "show variables like '%character% '"
7. View the installation path information for the MySQL source package
Ps-ef | grep MySQL
8. Modify the environment variables so that the mysqldump executes directly in the shell
Vi/etc/profile
Source/etc/profile
9. View the MySQL character set
Mysql-u Root-p-E "show variables like '%character% '"
10. Specifying the character set export database
Mysqldump-uroot-p ' db123 '--default-character-set=latin1 dbnamey >/opt/mysql_bak.sql
Egrep-v "#|\*|--|^$"/opt/mysql_bak.sql
11. View the character set of the created database
Mysql-uroot-p
Show CREATE Database Water_station\g

12.mysqldump-b parameter (no database exists when recovering)
Mysqldump-uroot-p ' db123 '-B dbname >/opt/mysql_bak_b.sql
Mysql-uroot-p ' db123 ' </opt/mysql_bak_b.sql

13. File Comparison
Diff Mysql_bak.sql Mysql_bak_b.sql

14. Optimize backup file size decrease input comment (debug debug)
Mysqldump-uroot-p ' db123 '--compact-b dbname>/opt/mysql_bak_b_compact.sql
Less/opt/mysql_bak_b_compact.sql

15. Specify the compression parameters to back up the database gzip
Mysqldump-uroot-p ' db123 '-B dbname | gzip >/opt/mysql_bak_b.sql.gz
Gunzip/opt/mysql_bak_b.sql.gz

16. Backing up a specified number of databases
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 '


This article is from the "Paraquat Susan" blog, so be sure to keep this source http://suxin.blog.51cto.com/535505/1836756

MySQL Backup restore

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.