前言
由于MySQL版本不兼容原因,你需要安装MySQL5.7,而不是安装MySQL8,那么你就麻烦了,Centos8默认是安装MySQL8的,因为Centos8的AppStream仓库只包含MySQL8的包,如果你在百度搜的方法不行,那么可以尝试一下我的办法在centos8中安装mysql5.7服务器。演示步骤如下:
演示
步骤1:添加MySQL5.7仓库
关闭Centos8中MySQL默认的AppStream仓库:
sudo dnf remove @mysql
sudo dnf module reset mysql && sudo dnf module disable mysql
目前还没有EL8版本的MySQL仓库,所以我们这里用EL7的代替,创建一个新的仓库文件:
sudo vi /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
步骤2:开始安装MySQL5.7
但步骤1的仓库文件创建完成后,就可以通过以下的命令在centos8中安装MySQL5.7了:
sudo dnf --enablerepo=mysql57-community install mysql-community-server
输入Y开始安装
步骤3:自动启动和安全配置
但第一次安装好MySQL5.7后,需要开启服务,实现重启自动启动:
sudo systemctl enable --now mysqld.service
然后获取mysql初始密码,用于后续安装配置操作
grep 'A temporary password' /var/log/mysqld.log |tail -1
接着开始对mysql进行安全配置,通过MySQL Secure Installation去修改密码、关闭root远程登陆权限,、删除匿名用户、删除测试数据库等:
sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
输入刚才获取的初始密码,开始配置:
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Yes
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?: Yes
Remove anonymous users?: Yes
Success.
Disallow root login remotely? : Yes
Success.
Remove test database and access to it? : Yes
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reload privilege tables now? (Press y|Y for Yes) : Yes
Success.
All done!
届时,就可以使用MySQL命令行工具操作数据库了
操作
测试数据库连接
$ mysql -u root -p
Enter password: <Enter Root Password>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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.28 |
+-----------+
1 row in set (0.00 sec)
mysql> QUIT
Bye
测试创建数据库和用户
mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.09 sec)
mysql> CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Strong34S;#";
Query OK, 0 rows affected (0.04 sec)
mysql> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
Query OK, 0 rows affected (0.02 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
测试删除数据库
mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.14 sec)
mysql> DROP USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.11 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> QUIT
Bye
额外:防火墙配置
允许远程3306端口连接
sudo firewall-cmd --add-service=mysql --permanent
sudo firewall-cmd --reload
添加可信网络
sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
service name="mysql" source address="10.10.10.0/24" accept'
- 2025年3月 (1)
- 2024年6月 (2)
- 2024年5月 (2)
- 2024年4月 (4)
- 2024年3月 (30)
- 2024年1月 (4)
- 2023年12月 (2)
- 2023年11月 (4)
- 2023年10月 (4)
- 2023年9月 (6)
- 2023年3月 (2)
- 2023年2月 (1)
- 2023年1月 (1)
- 2022年12月 (1)
- 2022年9月 (21)
- 2022年8月 (10)
- 2022年7月 (3)
- 2022年4月 (1)
- 2022年3月 (13)
- 2021年8月 (1)
- 2021年3月 (1)
- 2020年12月 (42)
- 2020年11月 (7)
- 2020年10月 (5)
- 2020年8月 (1)
- 2020年6月 (1)
- 2020年3月 (2)
- 2019年12月 (8)
- 2019年11月 (3)
- 2019年9月 (1)
- 2019年4月 (1)
- 2019年3月 (6)
- 2019年2月 (1)
- 2018年7月 (7)
- 1.asp.net mvc内微信pc端、H5、JsApi支付方式总结(5709)
- 2.各大搜索网站网站收录提交入口地址(3208)
- 3.Windows 10休眠文件更改存储位置(3176)
- 4.ECharts仪表盘实例及参数使用详解(3101)
- 5.windows 10安装myeclipse 10破解补丁cracker.jar、run.bat闪退解决办法(3009)
- 6.HTML5 WebSocket与C#建立Socket连接实现代码(2880)
- 7.华为鸿蒙系统清除微信浏览器缓存方法(2815)
- 8.CERT_HAS_EXPIRED错误如何解决(2300)
- 9.Js异步async、await关键字详细介绍(lambda表达式中使用async和await关键字)(2205)
- 10.HBuilder编辑器格式化代码(2126)