我是靠谱客的博主 妩媚绿茶,最近开发中收集的这篇文章主要介绍Centos 7.6通过rpm安装MySQL 5.7.38,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1、通过wget下载MySQL的rpm

wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.38-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.38-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.38-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.38-1.el7.x86_64.rpm

2、检查是否已经安装mysql

[root@localhost ~]# rpm -qa | grep mysql

如果安装过,上面命令会检查出相关安装信息,将其卸载,命令: rpm -e --nodeps mysql-5.xxx (这里以实际查找出来的名字为准)

[root@localhost ~]# rpm -e --nodeps mysql-xxx

3、MariaDB数据库是否存在

检查RHEL7自带的MariaDB数据库是否存在,mariadb与mysql会有冲突,如果有必须先卸载mariadb

[root@localhost ~]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

4、依次安装如下4个文件即可

[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.38-1.el7.x86_64.rpm
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm

 在安装server文件时,可能还会提示缺失其他依赖包,比如:net-tools,根据提示逐一下载相关依赖包并安装,全部依赖解决完后,再安装mysql-community-server这个rpm文件。缺失的依赖包推荐到这里下载:https://centos.pkgs.org/7/centos-x86_64/

至此,mysql5.7所有文件安装完毕,接下来就是开启服务了。

5、关闭MySQL服务

[root@localhost ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service

##修改配置文件my.cnf,设置免密登陆

[root@localhost ~]# vim /etc/my.cnf

在[mysqld]标签下 添加一句代码:(即可空密码登录mysql)

skip-grant-tables

6、开启mysql服务

[root@localhost ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service

# 添加到开机启动
[root@localhost ~]# systemctl enable mysqld.service


7、查看启动状态 

[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-05-10 14:45:17 CST; 1min 59s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 4564 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 3788 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4567 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─4567 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

May 10 14:44:36 admin systemd[1]: Starting MySQL Server...
May 10 14:45:17 admin systemd[1]: Started MySQL Server.

runing表示已经启动


8、查看MySql的版本号

[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using  EditLine wrapper

9、查看MySql初始密码

通过my.cnf文件找到log-error=/var/log/mysqld.log文件,在改文件中根据password关键字查询初始密码

[root@localhost ~]# vim /etc/my.cnf

找到初始密码之后,就可以开始登录了

[root@localhost ~]# grep "password" /var/log/mysqld.log

10、登录MySQL

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.38

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

---修改登录密码
mysql> alter user 'root'@'localhost' identified by "Hello@123";
Query OK, 0 rows affected (0.00 sec)

---开放连接权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Hello@123' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

安装完成!

最后

以上就是妩媚绿茶为你收集整理的Centos 7.6通过rpm安装MySQL 5.7.38的全部内容,希望文章能够帮你解决Centos 7.6通过rpm安装MySQL 5.7.38所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部