Mysql V8.0.35安装
官网地址:MySQL :: Download MySQL Community Server
- 下载【Mysql 8.0.35】压缩包
- 解压压缩包,仅保留6个安装文件即可
mysql-community-client-8.0.31-1.el7.x86_64.rpm mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm mysql-community-common-8.0.31-1.el7.x86_64.rpm mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm mysql-community-libs-8.0.31-1.el7.x86_64.rpm mysql-community-server-8.0.31-1.el7.x86_64.rpm
- 安装Mysql
# 1、检查MySQL需要的依赖
# 给安装MySQL需要的 /tmp文件夹赋权
chmod -R 777 /tmp
# 2、检查依赖
rpm -qa | grep libaio
# 如无
yum install libaio
rpm -qa | grep net-tools
# 如无
yum install net-tools
# 3、按照如下顺序 执行安装
#第1步安装mysql-community-common
rpm -ivh mysql-community-common-8.0.35-1.el7.x86_64.rpm
#第2步安装mysql-community-client-plugin
rpm -ivh mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm
#第3步安装mysql-community-libs
#如果报错mariadb-libs is obsoleted by mysql-community-libs-8.0.35-1.el7.x86_64
#执行 yum remove mariadb-libs
rpm -ivh mysql-community-libs-8.0.35-1.el7.x86_64.rpm
#第4步安装mysql-community-client
rpm -ivh mysql-community-client-8.0.35-1.el7.x86_64.rpm
#第5步安装mysql-community-icu-data-files
rpm -ivh mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm
#第6步安装mysql-community-server
#如果报错
#Failed dependencies:
# libnuma.so.1()(64bit) is needed by mysql-community-server-8.0.35-1.el7.x86_64
# libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-8.0.35-1.el7.x86_64
# libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-8.0.35-1.el7.x86_64
#执行 yum install numactl
rpm -ivh mysql-community-server-8.0.35-1.el7.x86_64.rpm
# 4、查看MySQL版本
mysql --version
# 或
mysqladmin --version
# 或 -i区分大小写,不然找不到
rpm -qa | grep -i mysql
# 5、初始化 生成root用户密码
mysqld --initialize --user=mysql
# 6、查看密码 [_#F8,8yL_n/0];[w;eabA+L2E*]
cat /var/log/mysqld.log
# 7、查看MySQL运行状态
systemctl status mysqld
# 8、启动MySQL服务
systemctl start mysqld
# 9、查询当前MySQL是否开机自启动
systemctl list-unit-files | grep mysqld.service
# 10、如果是disable,可设置开机自启动
systemctl enable mysqld.service
# 11、命令行登录
mysql -uroot -p
# 12、提示修改密码
alter user 'root'@'localhost' identified by 'Sdmc@2023ab';
#13、配置运行远程登录
use mysql #访问mysql库
update user set host = '%' where user = 'root'; #使root能再任何host访问
FLUSH PRIVILEGES; #刷新
- 配置Mysql 5.7兼容
a.配置不区分大小写lower_case_table_names
注意,重启后mysql密码会重置,需要重新查看mysql密码,才可以进行连接。
#1.MySQL8.0下修改此配置重启时禁止启动,如需更该需做如下操作
# a.停止MySQL服务
# b.删除数据目录(慎重),即删除/var/lib/mysql 目录
# c.在MySQL配置文件my.cnf中添加
lower_case_table_names=1
# d.启动服务器
# d.查看mysql密码
cat /var/log/mysqld.log
b.更改为InnoDB引擎或删除分区(未执行)
ALTER TABLE part ENGINE = INNODB;
c.设置兼容模式sql_mode
sql_mode=TRADITIONAL
- 配置Mysql 8.0主从复制
a.主服务器(Master)上修改配置文件(my.cnf)新增下面参数:
#1.MySQL8.0下修改此配置重启时禁止启动,如需更该需做如下操作
# a.停止MySQL服务
# b.删除数据目录(慎重),即删除/var/lib/mysql 目录
# c.在MySQL配置文件my.cnf中添加
lower_case_table_names=1
# d.启动服务器
# d.查看mysql密码
cat /var/log/mysqld.log
b.主服务器(Master)重启Mysql服务
systemctl restart mysqld
c.主服务器(Master)的数据库中创建用于复制的账户并授予相应的权限。
#1.登录MySQL
mysql -uroot -p
#2.切换MySQL
use mysql;
#3.创建用户
CREATE USER 'db_sync'@'%' IDENTIFIED BY 'Sdmc@123';
#4.授权账号复制权限
GRANT REPLICATION SLAVE ON *.* TO 'db_sync'@'%';
#5.刷新配置
FLUSH PRIVILEGES;
d.主服务器(Master)上执行以下命令获取当前二进制日志文件的名称和位置:
SHOW MASTER STATUS;
f.从服务器(Slave)上修改配置文件(my.cnf)/etc/my.cnf
server-id = 2
#中继日志文件的名称,用于从主服务器接收二进制日志事件。
relay-log = mysql-relay-bin
#从服务器的二进制日志文件的名称。
log_bin = mysql-bin
#不同步相关的库
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
重启Mysql服务
#重启MySQL服务 systemctl restart mysqld
g.登录从服务器(Slave)MySQL上根据主服务器建立的账号和show master status;显示的内容,修改以下命令配置主从复制(根据主服务上的配置进行修改)
#1.进入Mysql登录
mysql -uroot -p
#2.停止Mysql从服务
STOP SLAVE;
进行Master设置
CHANGE MASTER TO
#设置主服务器的IP
MASTER_HOST = '10.148.0.22',
#设置主服务器的账号
MASTER_USER = 'db_sync',
#设置主服务器的密码
MASTER_PASSWORD = 'Sdmc@123',
#主服务器数据库上的file值(不能有空格)
MASTER_LOG_FILE = 'mysql-bin.000001',
#主服务器数据库的Position值
MASTER_LOG_POS = 157,
get_master_public_key=1;
#启动Slave
start slave;
#查看主从同步开启状态 SHOW SLAVE STATUS\G;
注意:如果手欠,不小心把从库的数据删除后,导致同步失败;
重新执行
#停止Slave同步
stop slave;
#从小设置binlog行数
CHANGE MASTER TO
MASTER_HOST = '10.148.0.22',
MASTER_USER = 'db_sync',
MASTER_PASSWORD = 'Sdmc@123',
MASTER_LOG_FILE = 'mysql-bin.000001',
#主服务器数据库的Position值(最新的值)
MASTER_LOG_POS = 3429,
get_master_public_key=1;