MySQL之备份恢复

Posted zhaijihai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL之备份恢复相关的知识,希望对你有一定的参考价值。

1.备份的种类

逻辑备份:SQL语句的备份
物理备份:数据页备份

2.逻辑备份工具介绍

select xxxx from t1  into outfile /tmp/redis.txt
     mysql -uroot -p123 -e "select concat(‘hmset city_‘,id,‘ id ‘, id,‘ name ‘,name,‘ countrycode ‘,countrycode,‘ district ‘,district,‘ population ‘,population) from world.city limit 10 "|redis-cli     
     
    mysqldump 
    -u 
    -p 
    -S 
    -h 
    -P
    
    -A 全库备份
    mysqldump -uroot -p123 -A >/backup/full.sql
    -B 备份一个或多个指定库
    mysqldump -uroot -p123 -B world bbs  >/backup/wb.sql
    备份单库中的表
    mysqldump -uroot -p123  world city country  >/backup/ccc.sql
    
    --master-data=2       备份时记录二进制日志的状态
    --single-transaction  开启innodb热备功能
    -R 
    --triggers
    mysqldump -uroot -p123 -A --master-data=2 --single-transaction  -R   --triggers  >/backup/full.sql

3.主从复制

基于二进制日志完成的.

Master slave
3307---->3308

 

3.1  3307中创建复制用户

主库开启二进制日志

vim /data/3307/my.cnf 
log_bin=/data/3307/mysql-bin

[root@standby 3307]# systemctl restart mysqld3307

[root@standby backup]# mysql -S /data/3307/mysql.sock
grant replication slave on *.* to [email protected]‘10.0.0.%‘ identified by ‘123‘;

mysql> show master status
    -> ;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

 3.2  3308节点开启主从复制功能

[[email protected] 3307]# mysql -S /data/3308/mysql.sock

mysql> CHANGE MASTER TO
  MASTER_HOST=‘10.0.0.200‘,
  MASTER_USER=‘repl‘,
  MASTER_PASSWORD=‘123‘,
  MASTER_PORT=3307,
  MASTER_LOG_FILE=‘mysql-bin.000001‘,
  MASTER_LOG_POS=154;

mysql> start slave;
mysql> show slave statusG

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

 

以上是关于MySQL之备份恢复的主要内容,如果未能解决你的问题,请参考以下文章

mysql之备份与恢复

MySQL 之数据备份及恢复

MySQL 之数据备份及恢复

MySQL之备份恢复

MySQL之备份与恢复

MySQL备份与恢复之mysqldump工具