1、下载安装包
成都创新互联-专业网站定制、快速模板网站建设、高性价比侯马网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式侯马网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖侯马地区。费用合理售后完善,10多年实体公司更值得信赖。
wget https://cdn.MySQL.com//Downloads/MySQL-8.0/mysql-8.0.18-el7-x86_64.tar.gz
2、删除系统自带
rpm -qa |grep mysql rpm -qa |grep mariadb rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
3、修改配置文件
cat /etc/my.cnf [mysql] default-character-set=utf8 [mysqld] skip-name-resolve port = 3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data max_connections=200 character-set-server=utf8 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M log-bin=master-bin #master是master-bin,slave的是slave-bin server-id=1 #master为1,slave2 gtid_mode=ON enforce_gtid_consistency=ON binlog_checksum=NONE
4、初始化数据库
groupadd mysql useradd -r -g mysql -s /bin/false mysql cd /usr/local tar xvf mysql-8.0.18-el7-x86_64.tar.gz ln -s mysql-8.0.18-el7-x86_64 mysql cd mysql mkdir mysql-files chown mysql:mysql mysql-files chmod 750 mysql-files bin/mysqld --initialize --user=mysql bin/mysql_ssl_rsa_setup bin/mysqld_safe --user=mysql & cp support-files/mysql.server /etc/init.d/mysql.server
记住数据库的随机密码
#关闭命令
bin/mysqladmin -u root -p shutdown
#启动命令
bin/mysqld_safe --user=mysql &
5、设置环境变量:
cat /etc/profile.d/msyql MYSQL_HOME=/usr/local/mysql/ export PATH=$PATH:$MYSQL_HOME/bin
6、修改随机密码:
mysql -u root -p #输入初始化随机生成的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'hello123';
show master status; #查看master状态
7、为主从复制创建用户
CREATE USER 'econage'@'%' IDENTIFIED BY 'hello123';
GRANT REPLICATION SLAVE ON *.* TO econage@'%';
#mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password,把mysql用户登录密码加密规则还原成mysql_native_password. 不然会报错如下
#error connecting to master 'econage@192.168.0.56:3306' - retry-time: 60 retries: 1 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
ALTER USER 'econage'@'%' IDENTIFIED WITH mysql_native_password BY 'hello123'; #添加这一条命令即可
FLUSH PRIVILEGES;
8、查看连接是否正确:
mysql -ueconage -phello123 -h292.168.0.56 -e 'status;'
9、在slave进行连接master:
CHANGE MASTER TO
MASTER_HOST='192.168.0.56', #master主机ip
MASTER_USER='econage', #上面创建的用户
MASTER_PASSWORD='hello123', #用户密码
MASTER_LOG_FILE='master-bin.000002', #master的file文件名
MASTER_LOG_POS=474; # master的Position号
查看
show slave status\G #可能会状态不对,执行下面命令
stop slave;
start slave;
显示两个yes则正确。
10、验证
#分别在master和slave查看
show databases;
#在master去创建一个库
create database hello
#会发现slave上也有一个hello的库
文章题目:Linux二进制包安装Mysql8主从复制
网站网址:http://lswzjz.com/article/jdgccd.html