兩臺linux虛擬主機mysql
Linux版本CentOS7.四、MySQL 5.7linux
ip:192.168.3.100、192.168.3.108sql
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmbash
[root@BrianZhu /]# yum -y install mysql57-community-release-el7-10.noarch.rpm
服務器
[root@BrianZhu /]# yum -y install mysql-community-server
socket
[root@BrianZhu /]# systemctl start mysqld.service
ide
[root@BrianZhu /]# systemctl status mysqld.service
測試
此時MySQL已經開始正常運行,不過要想進入MySQL還得先找出此時root用戶的密碼,經過以下命令能夠在日誌文件中找出密碼:spa
[root@BrianZhu /]# grep "password" /var/log/mysqld.log
日誌
這時候咱們要把密碼規則改一下,執行下面sql就能夠了:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
1、配置master
master配置:
cat /etc/my.cnf
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=mysql-bin
server_id=226
bind-address=0.0.0.0
受權帳戶
GRANT REPLICATION SLAVE ON *.* to 'tom'@'%' identified by '123456';
第二步:
查看192.168.3.100MySQL服務器二進制文件名與位置
mysql>SHOW MASTER STATUS;
二 、salve 配置
cat /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=mysql-bin
server_id=220
在salve 執行以下語句:
change master to master_host='192.168.3.100',master_user='tom',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=1904;
mysql>START SLAVE; #開啓複製
mysql>SHOW SLAVE STATUS\G #查看主從複製是否配置成功
當看到Slave_IO_Running: YES、Slave_SQL_Running: YES才代表狀態正常
3、測試主從複製是否成功
192.168.3.100主MySQL操做(master):
mysql>create database aa;
mysql>use aa;
mysql>create table tab1(id int auto_increment,name varchar(10),primary key(id));
mysql>show databases;
mysql>show tables;
192.168.3.104從MySQL操做:
mysql>show databases;
mysql>show tables;
上面兩個結果圖可得知,兩主機達到了數據同步。主從複製的配置就是如此的簡單