主从服务器节点安装mysql5.7
检测系统是否自带安装mysql
yum list installed | grep mysql
删除系统自带的mysql及其依赖
命令:
yum -y remove mysql-libs.x86_64
给CentOS添加rpm源,并且选择较新的源
命令:
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
安装mysql 服务器
yum install mysql-community-server
启动mysql
service mysqld start
查看mysql是否自启动,并且设置开启自启动
命令:
chkconfig --list | grep mysqld
chkconfig mysqld on
修改root用户的密码
service mysqld stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root mysql
UPDATE user SET authentication_string=PASSWORD('xxx') where USER='root';
flush privileges;
service mysqld restart
问题
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user 'root'@'localhost' identified by 'xxxxxxxx';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
密码强度不够,密码需要包括大小写字母,长度不小于8位
主从配置
修改master节点
修改master节点配置
log-bin=mysql-bin #slave会基于此log-bin来做replication
server-id=1 #master的标示
innodb_flush_log_at_trx_commit=1
sync_binlog=1
配置支持复制的账号
grant replication SLAVE,RELOAD,SUPER on *.* to yqjj@'192.168.2.xx' identified by 'passwd';
查看master节点信息
mysql -uroot -ppasswd-e "show master status;"
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 595 | | | | +------------------+----------+--------------+------------------+-------------------+
配置slave节点信息
change master to master_host='xxxx',master_user='xxx',master_password='xxxx',master_log_file='mysql-bin.000001',master_log_pos=154; start slave;
其中
master_host为master主机的ip
master_user为支持主从复制的账号名称
master_password为支持主从复制账号的密码
master_log_file为支持主从复制的二进制文件
master_log_pos为主从复制的二进制文件位置
验证
在master新增表,看salve是否可以看到新增的表