1)/opt/software目录下上传MySQL安装包以及MySQL驱动jar包
链接: 百度网盘 请输入提取码 提取码: hp2x
mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
mysql-connector-java-5.1.37.jar
2)解压MySQL安装包
[shuidi@hadoop201 software]$ mkdir mysql_lib
[shuidi@hadoop201 software]$ tar -xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar -C mysql_lib/
3)卸载系统自带的mariadb
[shuidi@hadoop201 mysql_lib]$ sudo rpm -qa | grep mariadb | xargs sudo rpm -e --nodeps
4)安装MySQL依赖
[shuidi@hadoop201 mysql_lib]$ sudo rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.28-1.e################################# [100%]
[shuidi@hadoop201 mysql_lib]$ sudo rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.28-1.el7################################# [100%]
[shuidi@hadoop201 mysql_lib]$ sudo rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-compat-5.7.2################################# [100%]
5)安装mysql-client
[shuidi@hadoop201 mysql_lib]$ sudo rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
6)安装mysql-server
[shuidi@hadoop201 mysql_lib]$ sudo rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
注意:若出现以下错误
warning: 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
解决办法:
sudo yum -y install libaio
7)启动MySQL
[shuidi@hadoop201 mysql_lib]$ sudo systemctl start mysqld
8)查看MySQL密码
[shuidi@hadoop201 mysql_lib]$ sudo cat /var/log/mysqld.log | grep password
2023-05-29T08:32:10.810903Z 1 [Note] A temporary password is generated for root@localhost: T802/Vq,K7M;
配置MySQL
配置主要是root用户 + 密码,在任何主机上都能登录MySQL数据库。
1)用刚刚查到的密码进入MySQL(如果报错,给密码加单引号)
[shuidi@hadoop201 mysql_lib]$ sudo mysql -uroot -p"T802/Vq,K7M;"
2)设置复杂密码(由于MySQL密码策略,此密码必须足够复杂)
mysql> set password=password("Zan_1234");
3)非必选 更改MySQL密码策略
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4;
4)非必选 设置简单好记的密码
mysql> set password=password("123456");
5)进入MySQL库
mysql> use mysql
6)查询user表
mysql> select user, host from user;
7)修改user表,把Host表内容修改为%
mysql> update user set host="%" where user="root";
8)刷新
mysql> flush privileges;
9)退出
mysql> quit;