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

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native