时间:2021-07-01 10:21:17 帮助过:21人阅读
直接备份datadir=/var/lib/mysql
三、 在slave上操作
[root@localhost ~]# yum install mariadb-server -y
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=1 //必须唯一
character-set-server=utf8 //设置字符集
2. 启动mysql
[root@localhost ~]# systemctl start mariadb
3. 配置同步参数
MariaDB [(none)]> change master to
master_host=‘192.168.138.13‘,
master_user=‘root‘,
master_password=‘123456‘,
master_port=3306,
master_log_file=‘mysql-bin.000003‘,
master_log_pos=521;
4. 启动主从同步进程
MariaDB [(none)]> start slave;
5. 检查状态
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.138.13
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 521
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
看到两个yes说明配置成功
四、 测试
1.在slave上查看
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
2. 在master创建数据库
MariaDB [(none)]> create database testdb1;
Query OK, 1 row affected (0.00 sec)
3. 在slave查看
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testdb1 |
+--------------------+
4 rows in set (0.00 sec)
mysql 主从同步-读写分离
标签:relay backup emctl mysqld 字符 ted 文件 art roo