一定要会的mysql的rpm安装

日常程序开发的工作中,我们经常会用到mysql,有时需要做一些相关的测试,需要对mysql进行相关操作,但是公司的mysql是不可以随便乱操作的,所以这时我们需要自己安装一台自己的mysql是非常有必须要的。
常见的mysql的安装方式有yum,docker和rpm的安装。其中像yum和docker需要连接外网下载相关依赖,有时集群环境是隔绝外网的,这时就只能使用上传rpm包安装的方式了。
下面就进行相关操作的演示,其中操作系统环境是centos,mysql使用的是5.7的版本。
1.上传安装的mysql的相关依赖的rpn包

2.卸载本机自带的mysql,centos内置安装了 mariadb数据库,所以我们在安装mysql5.7之前,需要先卸载 mariadb数据库,执行下面的命令进行卸载。
rpm -qa | grep mariadb | xargs rpm -e --nodeps

3.安装mysql的依赖
rpm -ivh 01_mysql-community-common-5.7.16-1.el7.x86_64.rpm
rpm -ivh 02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm
rpm -ivh 03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm

4.安装mysql客户端
rpm -ivh 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm

5.安装mysql服务端
rpm -ivh 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm
执行安装会报如下的错,这个是因为确实相关的系统依赖导致的问题,主要安装对应依赖就可以了。

解决办法
yum install -y net-tools
yum install -y perl
重新执行安装命令就不报错了。

6.启动mysql服务
systemctl start mysqld

7.获取mysql生成的随机密码,mysql在初次启动的时候,会在mysql日志文件中生成一个随机密码。

首次登录之后,必须要修改密码

8.修改密码
登录成功后修改密码,mysql现在设置密码有规定,否则设置不成。这里是因为mysql设置了不同的安全策略,对应的解决办法是降低安装策略,或者是按照安全测试设置密码。
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

9.降低密码安全策略
set global validate_password_policy=0;
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
到这里,演示就已经完成了,需要同学们自己动手操作一下。