rhel7安装mysql5.7

时间:2022-05-09 06:03:51

原文地址:https://www.cnblogs.com/zq8421/p/10086361.html

---------------------红帽7----------------------

一、登录MySQL官网下载mysql

下载地址:https://dev.mysql.com/downloads/mysql/

因为有依赖关系,得下载下面五个包

mysql-community-client-5.7.24-1.el7.x86_64.rpm
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-devel-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
mysql-community-server-5.7.24-1.el7.x86_64.rpm

二、查看系统是否已经安装了mysql没有

代码 rpm -aq | grep mysql

Mariadb是rhel系统已经安装好了的,需要卸载掉,安装MySQL时可能有冲突,查看Mariadb,代码 rpm -qa | grep mariadb

三、卸载Mariadb

用 rpm -e 卸载,因为有有依赖关系,末尾加上 --nodeps不顾依赖关系强制卸载

rpm  -e  包名  --nodeps

四、创建安装文件夹

[[email protected] Desktop]# mkdir -p /usr/local/mysql

五、将下载好的5个安装包用 xshell 传过去

[[email protected] Desktop]# cd /usr/local/mysql/
[[email protected] mysql]# ls
mysql-community-client-5.7.24-1.el7.x86_64.rpm
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-devel-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
mysql-community-server-5.7.24-1.el7.x86_64.rpm

六、开始安装

各个文件是有依赖性的,必须按以下顺序安装

mysql-community-common-5.7.24-1.el7.x86_64.rpm

mysql-community-libs-5.7.24-1.el7.x86_64.rpm

mysql-community-client-5.7.24-1.el7.x86_64.rpm

imysql-community-server-5.7.24-1.el7.x86_64.rpm

mysql-community-devel-5.7.24-1.el7.x86_64.rpm

[[email protected] mysql]# rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.24-1.e################################# [100%]
[[email protected] mysql]# rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.24-1.el7################################# [100%]
[[email protected] mysql]# rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.24-1.e################################# [100%]
[[email protected] mysql]# rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.24-1.e################################# [100%]
[[email protected] mysql]# rpm -ivh mysql-community-devel-5.7.24-1.el7.x86_64.rpm 
warning: mysql-community-devel-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-devel-5.7.24-1.el################################# [100%]

mysql安装完毕后,是不会自动启动的,但是第一次启动后,以后开机都是自启的,没有第一次启动之前,也是没有密码的。当你第一次启动MySQL服务器的时候,mysql自己就会自己做很多事情,其中之一重要的就是初始密码

七、 启动mysql服务

[[email protected] mysql]# systemctl start mysqld.service 
[[email protected] mysql]# systemctl status mysqld.service 
mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
   Active: active (running) since Sat 2018-12-08 00:13:35 CST; 10s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 4150 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 4072 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4153 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─4153 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...

Dec 08 00:13:35 localhost.localdomain systemd[1]: Started MySQL Server.

八、查看初始密码

启动之后密码就初始化好了,可以用 cat /var/log/mysqld.log 查看

rhel7安装mysql5.7

九、登录MySQL

登录进去是没有权限任何操作的,必须修改密码

登录代码 mysql -u root -p 回车就让你输入密码

[[email protected] mysql]# mysql -uroot -p
Enter password:       //输入密码

rhel7安装mysql5.7

十、修改密码

mysql> set password for 'root'@'localhost'='密码'    //密码必须要符合要求,八位及以上,需要大小写、数字和特殊字
mysql> set password for 'root'@'localhost'='qweQWE123<';
Query OK, 0 rows affected (0.00 sec)

到这里就安装完成了