MariaDB主从备份记录
2016-07-19 17:09
447 查看
一、预期效果:
环境: centos 6.5 mariadb 10.0.14 (mysql -V)
主服务器:192.168.5.206 从服务器:192.168.5.207 主服务器数据库有任何变动,从服务会跟着变动。
二、前期准备:
确保主从数据库数据一致。
三、配置:
1⃣️ 主服务器:vi /etc/my.cnf.d/server.cnf 添加如下配置,确保log-bin文件存在,所属用户组与mysql一致并增加X权限。
2⃣️ 主服务器增加同步账户,从服务器登录该账号同步主服务器的数据。
3⃣️ 从服务器:vi /etc/my.cnf.d/server.cnf 添加如下配置,同样保证salve-bin , relay-bin 文件存在,所属用户组与mysql一致并增加X权限。
4⃣️ 主从配置:
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
如果此处出现错误, MariaDB [(none)]> reset slave; 重新从服务器重新上述操作。
MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.5.206
Master_User: backup1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000004
Read_Master_Log_Pos: 23773
Relay_Log_File: relay-bin.000004
Relay_Log_Pos: 24061
Relay_Master_Log_File: master-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 23773
Relay_Log_Space: 24640
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec)
ERROR: No query specified
至此,已经OK了。
环境: centos 6.5 mariadb 10.0.14 (mysql -V)
主服务器:192.168.5.206 从服务器:192.168.5.207 主服务器数据库有任何变动,从服务会跟着变动。
二、前期准备:
确保主从数据库数据一致。
mysqldump -uroot -p 数据库名 > db.sql mysql -uroot -p 数据库名 < db.sql
三、配置:
1⃣️ 主服务器:vi /etc/my.cnf.d/server.cnf 添加如下配置,确保log-bin文件存在,所属用户组与mysql一致并增加X权限。
# this is only for the mysqld standalone daemon [mysqld] log-bin=/var/lib/mysql/log/master-bin server-id=1
2⃣️ 主服务器增加同步账户,从服务器登录该账号同步主服务器的数据。
MariaDB [(none)]> GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO backup@'192.168.5.207' IDENTIFIED BY 'password'; MariaDB [(none)]> Flush privileges; 注:backup:用户名 192.168.5.207:从服务器的IP(IP限制) password:登录密码
3⃣️ 从服务器:vi /etc/my.cnf.d/server.cnf 添加如下配置,同样保证salve-bin , relay-bin 文件存在,所属用户组与mysql一致并增加X权限。
# this is only for the mysqld standalone daemon [mysqld] log-bin=/var/lib/mysql/log/salve-bin server-id=2 relay-log=/var/lib/mysql/log/relay-bin log-slave-updates=1 read-only=1 重启从服务器 service mysql restart
4⃣️ 主从配置:
主服务器: MariaDB [(none)]> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-bin.000003 | 17030 | | | +-------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
从服务器: MariaDB [(none)]> change master to master_host='192.168.5.206', -> master_user='backup', -> master_password='password', -> master_log_file='master-bin.000003', -> master_log_pos=0; Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
如果此处出现错误, MariaDB [(none)]> reset slave; 重新从服务器重新上述操作。
MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.5.206
Master_User: backup1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000004
Read_Master_Log_Pos: 23773
Relay_Log_File: relay-bin.000004
Relay_Log_Pos: 24061
Relay_Master_Log_File: master-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 23773
Relay_Log_Space: 24640
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec)
ERROR: No query specified
至此,已经OK了。
相关文章推荐
- 淘宝内部分享:MySQL & MariaDB性能优化
- nginx as Database Load Balancer for MySQL or MariaDB Galera Cluster
- centos7 下安装mariadb10两种方法
- CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置
- linux 系统下面mariadb启动失败
- Linux mysql mariadb
- MySQL并发复制系列三:MySQL和MariaDB实现对比
- 在 CentOS 7 CPanel 服务器上安装 MariaDB 10
- MariaDB10.2.X-新特性1-支持分析函数
- 燃情7月,ACMUG厦门、上海双城技术沙龙及MySQL/MariaDB创始人Monty中国行活动
- MySQL或者MariaDB里面sql_mode的设置详解
- centos7 mysql: mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
- centos7 安装 mariadb(mysql的一个分支) 的正确命令
- 查看编译完成nginx,apache,mysql,php,mariadb参数
- debian8.4中mariadb数据备份脚本
- 燃情7月,ACMUG厦门、上海双城技术沙龙及MySQL/MariaDB创始人Monty中国行活动
- Percona/MariaDB/MySQL
- mariadb数据库主从设置
- 在 Ubuntu 16.04 为 Nginx 服务器安装 LEMP 环境(MariaDB,PHP 7 并支持 HTTP 2.0)
- 在 Ubuntu 16.04 为 Nginx 服务器安装 LEMP 环境(MariaDB,PHP 7 并支持 HTTP 2.0)