CentOS 8安装MySQL 5.7

关闭CentOS 8中MySQL默认的AppStream仓库

[root@prod-mysql01 ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core)
[root@prod-mysql01 ~]# dnf remove @mysql
CentOS-8 - AppStream                                                                                                                                                         43 MB/s | 8.1 MB     00:00    
CentOS-8 - Base                                                                                                                                                              25 MB/s | 3.6 MB     00:00    
CentOS-8 - Extras                                                                                                                                                           147 kB/s | 9.8 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                               39 MB/s |  10 MB     00:00    
Unable to match profile in argument mysql
Dependencies resolved.
Nothing to do.
Complete!
[root@prod-mysql01 ~]# dnf module reset mysql && sudo dnf module disable mysql
Last metadata expiration check: 0:00:07 ago on Fri 02 Jul 2021 11:05:44 AM CST.
Dependencies resolved.
Nothing to do.
Complete!
Last metadata expiration check: 0:00:08 ago on Fri 02 Jul 2021 11:05:44 AM CST.
Dependencies resolved.
============================================================================================================================================================================================================
 Package                                          Architecture                                    Version                                            Repository                                        Size
============================================================================================================================================================================================================
Disabling modules:
 mysql                                                                                                                                                                                                     

Transaction Summary
============================================================================================================================================================================================================

Is this ok [y/N]: y
Complete!

目前还没有CentOS 8的MySQL仓库,所以我们这里用CentOS 7的代替,创建新的仓库文件

[root@prod-mysql01 ~]# cat /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0

在CentOS8中安装MySQL5.7

[root@prod-mysql01 ~]# dnf --enablerepo=mysql57-community install mysql-community-server

配置开机自启动

[root@prod-mysql01 ~]# systemctl enable --now mysqld.service

获取MySQL初始密码

[root@prod-mysql01 ~]# grep 'A temporary password' /var/log/mysqld.log
2021-07-02T03:27:35.812766Z 1 [Note] A temporary password is generated for root@localhost: Etpo_!Q?I0nm

数据库初始化

[root@prod-mysql01 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

登录数据库

[root@prod-mysql01 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> select version();
+-----------+
| version() |
+-----------+
| 5.7.34    |
+-----------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

  参考文档:https://blog.csdn.net/wudics/article/details/107573626——centos8安装mysql5.7

上一篇:SQL必知必会


下一篇:Mysql正则表达式整理