安装mysql的我就不写了,之前已经写过。
现有两台虚拟机
主 192.168.200.101 (mysql1)
从 192.168.200.102 (mysql2)
主 编辑vi /etc/my.cnf 配置文件 在mysqld里加入
log-bin=mysql-bin
server-id=101 #id号一般都是ip后两位

从
[root@mysql2 ~]# vi /etc/my.cn
[mysqld]
log-bin=mysql-bin
server-id=102
之后就是授权之类的了
主
MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by '000000';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant replication slave on *.* to 'user'@'%' identified by '000000';
密码6个0 允许192.168.200.102主机连接
从
MariaDB [(none)]> change master to master_host='192.168.200.101',master_user='user',master_password='000000';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G;
从上到下依次是配置主从数据库之间的连接信息
开启从节点服务
查看从节点服务状态
下面是验证
主
create database test; 创建一个名为test的库
use test;
create table company(id int not null primary key,name varchar(25),addr varchar(255)); 创建一个表
insert into company values(1,'alibaba','china'); 添加数据
MariaDB [test]> select * from company; 查看刚才创建的表
+----+---------+-------+
| id | name | addr |
+----+---------+-------+
| 1 | alibaba | china |
+----+---------+-------+
1 row in set (0.00 sec)
从节点的查看
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
发现test 在从节点的库中,很OK
545

被折叠的 条评论
为什么被折叠?



