快捷菜单
常用功能一站直达
更多功能请点顶栏「快捷菜单」
centos7安装 6.0以下mysql ?
在 CentOS 7 上安装 MySQL 5.7 或更低版本(如 MySQL 5.6) 的步骤如下。由于 MySQL 官方已停止维护旧版本,推荐使用 MariaDB(MySQL 分支)作为替代。若仍需安装原生 MySQL 5.6/5.7,需通过官方历史仓库或手动编译安装。
MySQL 5.7 是较旧的稳定版本,仍被部分老项目使用。以下是安装步骤:
1sudo rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm1sudo yum install mysql-community-server -y
2
3#用下面这个
4sudo yum install mysql-community-server -y --nogpgcheck1sudo systemctl start mysqld
2sudo systemctl enable mysqldMySQL 5.7 首次安装会生成临时密码:
1sudo grep 'temporary password' /var/log/mysqld.log输出类似:
12023-01-01T00:00:00.000000Z 1 [Note] A temporary password is generated for root@localhost: Abc123!@#运行安全脚本:
1sudo mysql_secure_installation按提示操作:
MyNewPass@123)。1mysql -u root -p输入密码后进入 MySQL Shell,运行:
1SELECT VERSION();应输出 5.7.x。
MySQL 5.6 已停止支持,需手动启用旧版仓库:
1sudo yum-config-manager --disable mysql80-community1sudo yum-config-manager --enable mysql56-community1sudo yum install mysql-community-server -y后续步骤与 MySQL 5.7 相同(启动服务、安全配置等)。
如果项目兼容 MariaDB,推荐使用它(更安全且持续更新):
1sudo yum install mariadb-server mariadb -y1sudo systemctl start mariadb
2sudo systemctl enable mariadb
3sudo mysql_secure_installation1mysql -V输出类似:
1mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64)1sudo yum remove mysql-server mysql-community-server
2sudo rm -rf /var/lib/mysql编辑配置文件:
1sudo vi /etc/my.cnf添加:
1[mysqld]
2validate_password_policy=LOW
3validate_password_length=4重启 MySQL:
1sudo systemctl restart mysqld登录 MySQL 后执行:
1GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
2FLUSH PRIVILEGES;并开放防火墙:
1sudo firewall-cmd --add-service=mysql --permanent
2sudo firewall-cmd --reload| 版本 | 状态 | 推荐场景 |
|---|---|---|
| MySQL 5.6 | 已停止支持 | 仅限遗留系统 |
| MySQL 5.7 | 维护至 2023-10 | 旧项目过渡 |
| MariaDB 5.5 | 持续维护 | 兼容 MySQL 5.6 |
如果有特殊需求(如特定补丁版本),可考虑手动编译安装,但复杂度较高。
1[root@localhost conf.d]#sudo grep 'temporary password' /var/log/mysqld.log
22025-06-08T00:42:17.640714Z 1 [Note] A temporary password is generated for root@localhost: 1;,L(nNjJ9&Z
3[root@localhost conf.d]#sudo mysql_secure_installation
4
5Securing the MySQL server deployment.
6
7Enter password for user root:
8
9The existing password for the user account root has expired. Please set a new password.
10
11New password:
12
13Re-enter new password:
14The 'validate_password' plugin is installed on the server.
15The subsequent steps will run with the existing configuration
16of the plugin.
17Using existing password for root.
18
19Estimated strength of the password: 100
20Change the password for root ? ((Press y|Y for Yes, any other key for No) : no
21
22 ... skipping.
23By default, a MySQL installation has an anonymous user,
24allowing anyone to log into MySQL without having to have
25a user account created for them. This is intended only for
26testing, and to make the installation go a bit smoother.
27You should remove them before moving into a production
28environment.
29
30Remove anonymous users? (Press y|Y for Yes, any other key for No) : yes
31Success.
32
33
34Normally, root should only be allowed to connect from
35'localhost'. This ensures that someone cannot guess at
36the root password from the network.
37
38Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no
39
40 ... skipping.
41By default, MySQL comes with a database named 'test' that
42anyone can access. This is also intended only for testing,
43and should be removed before moving into a production
44environment.
45
46
47Remove test database and access to it? (Press y|Y for Yes, any other key for No) : yes
48 - Dropping test database...
49Success.
50
51 - Removing privileges on test database...
52Success.
53
54Reloading the privilege tables will ensure that all changes
55made so far will take effect immediately.
56
57Reload privilege tables now? (Press y|Y for Yes, any other key for No) : yes
58Success.
59
60All done!
61[root@localhost conf.d]#日历 · 精选 · 友链 · 更多
如果内容对你有帮助,欢迎请我喝杯咖啡 ☕



One的公众号
爱折腾博客的小白