CentOS7安装MySQL5.7

1.下载RPM安装包

mysql的rpm包,安装起来简单,解压版的mysql还需要做许多配置,稍有不慎就会出错!!!

  • 下载后的安装包是这个样子的

    image-20211013182832566

2.安装依赖

2.1 查看linux上是否已经安装了mysql,有则卸载

一般centos7默认安装了mariadb,这里把它卸载。

[root@jxe ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@jxe ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

2.2 安装mysql5.7所需要的依赖

[root@jxe ~]# yum install -y  libaio perl net-tools

3 安装mysql5.7

3.1 解压MySQL5.7安装包

解压完后会有很过rpm文件,这些就是我们需要安装的。

[root@jxe ~]# tar -xvf  mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-5.7.35-1.el7.x86_64.rpm
mysql-community-common-5.7.35-1.el7.x86_64.rpm
mysql-community-devel-5.7.35-1.el7.x86_64.rpm
mysql-community-embedded-5.7.35-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.35-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.35-1.el7.x86_64.rpm
mysql-community-libs-5.7.35-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.35-1.el7.x86_64.rpm
mysql-community-server-5.7.35-1.el7.x86_64.rpm
mysql-community-test-5.7.35-1.el7.x86_64.rpm

3.2 安装MySQL5.7

rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm

3.3 运行MySQL

# 启动MySQL服务
[root@jxe ~]# systemctl start mysqld
# 查看MySQL运行状态
[root@jxe ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html


# 设置为开机自启
[root@jxe ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

3.4 修改密码

  1. 查看临时密码

    [root@jxe ~]# grep password /var/log/mysqld.log
    2021-10-13T10:34:01.464297Z 1 [Note] A temporary password is generated for root@localhost: Cn)ypbPee23u
  2. 修改密码

    1. 用临时密码登录mysql -uroot -p

    2. 修改成新的密码:

      mysql> set password = password("Jxe123456!@#");
  3. 开启远程连接,允许远程连接数据库

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Jxe123456!@#' WITH grant OPTION;
    # 刷新权限
    mysql> flush privileges;
  4. MySQL默认配置文件/etc/my.cnf