注:我是在已有rpm安装的mysql版本的基础上安装mysql-8.0.33的操作
首先停掉服务,然后听到mysql服务
systemctl stop mysqld
** 查看当前libc.so 它会支持多个版本
strings /lib64/libc.so.6 | grep ^GLIBC
根据GLIBC的支持下载官方的源码包,并上传到Linux服务器
1:解压mysql源码包
tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
改名
mv mysql-8.0.33-linux-glibc2.12-x86_64 mysql-8.0.33
chown -R mysql:mysql mysql-8.0.33
配置文件my.cnf
vim /db/mysql-8.0.33/my.cnf
------------------------------------------------------------------------------
---------------------------------------------------------------------------
4:初始化mysql
mysqld --defaults-file=/db/mysql-8.0.33/my.cnf --initialize --user=mysql --basedir=/db/mysql-8.0.33 --datadir=/db/mysql-8.0.33/data
查临时密码
grep "password" /db/mysql-8.0.33/log/mysqld.log
启动mysql数据库
mysqld_safe --defaults-file=/db/mysql-8.0.33/my.cnf --user=mysql &
7:连接mysql数据库
mysql -uroot -p -S /db/mysql-8.0.33/data/mysql.sock
修改数据库密码,即开启远程连接(连接数据库后的操作)
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;
use mysql;
update user set host='%' where user='root';
flush privileges;
grant all privileges on *.* to root@'%';
flush privileges;
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
create database LICENCE_AUTH;
use LICENCE_AUTH;
alter database LICENCE_AUTH default character set utf8;
set names utf8;
exit;
10:关闭mysql服务
mysqladmin -uroot -p shutdown -S /db/mysql-8.0.33/data/mysql.sock
重启mysql服务
mysqld_safe --defaults-file=/db/mysql-8.0.33/my.cnf --user=mysql &
测试连接
telnet 127.0.0.1 3306
————————————————————————————————————————————————————————————————————————
配置主从复制
把my.cnf配置文件的**主从配置都取消注释
**之后关闭mysql服务重新启服务
mysqladmin -uroot -p shutdown -S /db/mysql-8.0.33/data/mysql.sock
mysqld_safe --defaults-file=/db/mysql-8.0.33/my.cnf --user=mysql &
在master-1和master-2分别操作
SELECT @@server_id; # 检查配置文件中的server_id是否生效
在master-1上操作
create user 'LICENCE_AUTH'@'192.168.130.95' identified with mysql_native_password by '123456';
grant replication slave on *.* to 'LICENCE_AUTH'@'192.168.130.95';
flush privileges;
show master status;
在master-2上操作
create user 'LICENCE_AUTH'@'192.168.130.94' identified with mysql_native_password by '123456';
grant replication slave on *.* to 'LICENCE_AUTH'@'192.168.130.94';
flush privileges;
show master status;
在master-2上配置同步信息
unlock tables;
change master to
master_host='192.168.130.94',
master_user='LICENCE_AUTH',
master_password='123456',
master_log_file='log-bin.000001', # master_log_file是File的值
master_log_pos=876; # master_log_pos是Position的值
start slave; # 启动slave同步进程
show slave status\G; # 查看是否有误
在master-1上配置同步信息
unlock tables; # 取消表锁
change master to master_host='192.168.130.95',master_user='LICENCE_AUTH',master_password='123456',master_log_file='log-bin.000001',master_log_pos=876;
start slave; # 启动slave同步进程
show slave status\G; # 查看是否有误
6:如果有不同步的就执行如下操作(有误的mysql)
stop slave; # 停止有误的slave线程
reset slave; # 重新设置slave线程(需要获取另一台mysql的show master status;的结果)
6.1:在另一台mysql上执行
flush tables with read lock\G;
flush privileges;
show master status;
6.2:在有误的mysql上执行
change master to master_host='192.168.130.95',master_user='LICENCE_AUTH',master_password='123456',master_log_file='binlog.000002',master_log_pos=1301;
start slave; # 启动slave线程
show slave status\G;
测试同步
在master-2操作
use LICENCE_AUTH;
show tables;
CREATE TABLE IF NOT EXISTS `A`( `id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(100) NOT NULL);
INSERT INTO A(name) values('test1');
SELECT * FROM A;
在master-1操作
use LICENCE_AUTH;
show tables;
SELECT * FROM A;
INSERT INTO A(name) values('test2');
SELECT * FROM A;
来源地址:https://blog.csdn.net/Rivennew/article/details/130925113