CentOS7安装mysql5.7

198 阅读3分钟

开始

官网,点击 DOCUMENTATION,点击 MySQL 8.0Reference Manual,点击 Installing and Upgrading MySQL,点击Installing MySQL on Linux,最后点击 version,选择你的安装版本

image.png

本次使用2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository安装方式

配置存储库

MySQL Yum 存储库页面 ( dev.mysql.com/downloads/r… )

下载

wget https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm

对于基于 EL7 的系统执行

sudo yum install mysql80-community-release-el7-5.noarch.rpm

选择发布系列

# 查看 MySQL Yum 存储库
[root@rabbitmq2 home]#  yum repolist all | grep mysql

#开启5.7
[root@rabbitmq2 home]# sudo yum-config-manager --enable mysql57-community

#关闭8.0
[root@rabbitmq2 home]# sudo yum-config-manager --disable mysql80-community

#验证是否启用和禁用了正确的子存储库
#可见mysql是57版本
[root@rabbitmq2 home]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64     MySQL Connectors Community             230
mysql-tools-community/x86_64          MySQL Tools Community                  138
mysql57-community/x86_64              MySQL 5.7 Community Server             564

安装 MySQL

[root@rabbitmq2 home]# sudo yum install -y mysql-community-server
xxx

Installed:
  mysql-community-libs.x86_64 0:5.7.37-1.el7                  mysql-community-libs-compat.x86_64 0:5.7.37-1.el7                  mysql-community-server.x86_64 0:5.7.37-1.el7                 

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.37-1.el7                                                   mysql-community-common.x86_64 0:5.7.37-1.el7                                                  

Replaced:
  mariadb-libs.x86_64 1:5.5.68-1.el7                                                                                                                                                            

Complete!

这将安装 MySQL 服务器的软件包 ( mysql-community-server) 以及运行服务器所需的组件的软件包,包括客户端的软件包 ( mysql-community-client)、客户端和服务器的常见错误消息和字符集 ( mysql-community-common) 以及共享的客户端库 ( mysql-community-libs) .

启动 MYSQL

sudo service mysqld start

查看状态

# running表示启动成功
[root@rabbitmq2 home]# sudo service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-03-21 08:42:03 EDT; 46s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2858 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 2809 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2861 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2861 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Mar 21 08:41:59 rabbitmq2 systemd[1]: Starting MySQL Server...
Mar 21 08:42:03 rabbitmq2 systemd[1]: Started MySQL Server.

重置密码

#查看初始密码
[root@rabbitmq2 home]# sudo grep 'temporary password' /var/log/mysqld.log
2022-03-21T12:42:00.698412Z 1 [Note] A temporary password is generated for root@localhost: (b0_P>VhGils

#登录 
[root@rabbitmq2 home]# mysql -uroot -p
Enter password: (b0_P>VhGils
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
#当前版本
Server version: 5.7.37

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 'MyNewPass4!';
Query OK, 0 rows affected (0.00 sec)

#输入quit退出
mysql> quit

登录

[root@rabbitmq2 home]# mysql -uroot -p
#输入新密码
Enter password: MyNewPass4!
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37 MySQL Community Server (GPL)

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>


解决



# 1130 Host is not allowed to connect to this MySQL server

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)