mysql/mysql-server 8.0 主从
cd docker
mkdir -p mysql1/config/ mysql2/config/ mysql3/config/
cp my.cnf mysql1/config/
cp my.cnf mysql2/config/
cp my.cnf mysql3/config/
chmod -R 755 mysql*
docker run --name=mysql1 -v /root/docker/mysql1/config/my.cnf:/etc/my.cnf -v /root/docker/mysql1/data:/var/lib/mysql -d -p 19013:3306 mysql/mysql-server
docker run --name=mysql2 -v /root/docker/mysql2/config/my.cnf:/etc/my.cnf -v /root/docker/mysql2/data:/var/lib/mysql -d -p 19014:3306 mysql/mysql-server
docker run --name=mysql3 -v /root/docker/mysql3/config/my.cnf:/etc/my.cnf -v /root/docker/mysql3/data:/var/lib/mysql -d -p 19015:3306 mysql/mysql-server
docker stop mysql1 mysql2 mysql3
docker start mysql1 mysql2 mysql3
# status 为 healthy 说明启动成功
docker logs mysql1 2>&1 | grep GENERATED
docker logs mysql2 2>&1 | grep GENERATED
docker logs mysql3 2>&1 | grep GENERATED
docker exec -it mysql1 mysql -uroot -p
docker exec -it mysql2 mysql -uroot -p
docker exec -it mysql3 mysql -uroot -p
->输入密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
use mysql;
update user set host='%' where user ='root';
select host,user,plugin from user;
FLUSH PRIVILEGES;
# master修改 --------------------------------------
vim mysql1/config/my.cnf
[mysqld]
log-bin=/var/lib/mysql/binlog
server-id=1
# 进入mysql1
show master status;
binlog.000003 | 156
CREATE USER 'repl'@'172.24.20.1' IDENTIFIED WITH 'mysql_native_password' BY 'slavepass';#创建用户
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'172.24.20.1';#分配权限
flush privileges; #刷新权限
#slave修改 -----------------------------------------
vim mysql2/config/my.cnf
[mysqld]
server-id=2 #设置server-id,必须唯一
# 进入slave
CHANGE MASTER TO MASTER_HOST='sddphp.cn',
MASTER_PORT=19013,
MASTER_USER='repl',
MASTER_PASSWORD='slavepass',
MASTER_LOG_FILE='binlog.000003',
MASTER_LOG_POS=5402; #后面两个参数的值与主库保持一致
start slave;
stop slave;
show slave status\G;
laravel连不上mysql8.0?
alter user 'root'@'%' identified with mysql_native_password by '123456';