Backing up a database method using Mysqldump

Source: Internet
Author: User
Tags ming

Database: Oldcat

Database tables: T_oldcat

1, first in the OPT directory to create a backup directory

[Email protected] ~]# mkdir-p/opt/mysql/data_bak

2. Query the database table:

[Email protected] ~]# MYSQL-UOLDCAT-POLDCAT123-E "Use Oldcat;select * from T_oldcat" +----+--------+| ID |  Name |+----+--------+| 1 |  CFL | | 2 |  Heheh | | 3 |  xx | | 4 |  Xiao Ming | | 5 |  Ali | | 6 | AA |+----+--------+6 rows in Set (0.00 sec)

3. Back up the database and check the backup file

[[email protected] ~]# mysqldump -uoldcat - poldcat123 > /opt/mysql/data_bak/oldcat_bak_b.sql[[email protected] ~]# ll / opt/mysql/data_bak/Total dosage  4-rw-r--r--.  1 root root 203 12 month   4 21:16  oldcat_bak_B.sql[[email protected] ~]# egrep -v  "#|\*|--|^$"  /opt/mysql/ data_bak/oldcat_bak_b.sql use  ' oldcat ';D rop table if exists  ' t_oldcat '; create table  ' T_oldcat '   (   ' id '  int (one)  not null auto_increment,    ' name '  varchar  DEFAULT NULL,  PRIMARY KEY  (' id '))   engine=innodb auto_increment=7 default charset=utf8; lock tables  ' t_oldcat '  WRITE;INSERT INTO  ' T_oldcat '  VALUES  (1, ' CFL '), (2, ' Heheh '), (3, ' xx '), (4, ' xiaoming '), (5, ' Ali '), (6, ' AA '); Unlock tables; 

[[email protected] ~]# mysql -uoldcat -poldcat123 -e  "show databases; Drop database oldcat;show databases "+--------------------+| database            |+--------------------+| information_schema | |  mysql              | |  oldcat             | |  performance_schema | |  test               |+-------- ------------+ +--------------------+| database            |+--------------------+| information_schema | |  mysql              | |  performance_schema | |  test               |+--------------------+ 

5. Perform recovery and check recovery results

[Email protected] ~]# mysql-uoldcat-poldcat123 </opt/mysql/data_bak/oldcat_bak_b.sql[[email protected] ~]# mysql- Uoldcat-poldcat123-e "Show Databases" +--------------------+| Database |+--------------------+| Information_schema | | MySQL | | Oldcat | | Performance_schema | | Test |+--------------------+

6, Query Oldcat database t_oldcat table

[Email protected] ~]# MYSQL-UOLDCAT-POLDCAT123-E "Use oldcat;select * from T_oldcat;" +----+--------+| ID |  Name |+----+--------+| 1 |  CFL | | 2 |  Heheh | | 3 |  xx | | 4 |  Xiao Ming | | 5 |  Ali | | 6 | AA |+----+--------+


Backing up a database method using Mysqldump

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.