当前位置: 代码迷 >> 综合 >> CenterOS 安装Mysql,并配置主从复制
  详细解决方案

CenterOS 安装Mysql,并配置主从复制

热度:86   发布时间:2024-01-30 02:40:26.0

CenterOS 安装Mysql,并配置主从复制

cd /usr/local/src/
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpmyum install mysql-community-serversystemctl start mysqld.servicesystemctl status mysqld.service// 获取安装的默认密码
grep 'temporary password' /var/log/mysqld.log// 连接MySQL
mysql -uroot -p// 修改默认密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '1@3$qWeR';// 切换数据库
use mysql
// 允许远程连接
update user set host='%' where user='root';
// 查看 user
select host,user,plugin from user;// 修改密码强度策略
// 查看
SHOW VARIABLES like 'validate_password%';
// 修改
set global validate_password_policy=0;
set global validate_password_length=4;
set global validate_password_check_user_name=0;FLUSH PRIVILEGES;// 将密码修改为简单密码
ALTER USER 'root'@'%' IDENTIFIED BY 'root';

主从复制一主一从

主机my.cnf

//删除mysql环境
配置主机
my.cnf:
#主服务器唯一ID
server-id=1
#启用二进制日志
log-bin=mysql-bin
#设置不要复制的数据库(可设置多个)
binlog-ignore-db=mysql binlog-ignore-db=information_schema
#设置需要复制的数据库
binlog-do-db=mydb
#设置logbin格式
binlog_format=STATEMENT

命令行mysql:

GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123456';
show master status;
记录下File和Position的值

从机配置my.cnf

#从服务器唯一ID
server-id=2
#启用中继日志
relay-log=mysql-relay

命令行mysql

CHANGE MASTER TO MASTER_HOST='192.168.0.104',
MASTER_USER='slave',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=582;启动从服务器复制功能
start slave;查看从服务器状态
show slave status\G;停止从机
stop slave;
  相关解决方案