MySQL 的mysql_secure_installation安全脚本执行过程介绍

1.设置 MySQL root 用户密码。

2.删除匿名用户。

3.禁止 root 用户远程登录。

4.删除测试数据库。

5.重新加载权限表。

以下是执行 mysql_secure_installation 的详细步骤:

步骤 1:启动 mysql_secure_installation 脚本

打开终端并执行以下命令:

sudo mysql_secure_installation

步骤 2:输入当前的 MySQL root 密码

如果这是第一次设置,MySQL root 用户没有密码,你可以直接按 Enter 键。否则,输入当前的 root 密码。

步骤 3:设置新的 root 密码

你会被询问是否要设置新的 root 密码。如果当前没有设置 root 密码,建议设置一个强密码。输入 Y 并按 Enter,然后按照提示设置密码。

步骤 4:删除匿名用户

删除匿名用户账户,防止未授权用户登录 MySQL。输入 Y 并按 Enter。

5:禁止 root 用户远程登录

为了提高安全性,建议禁止 root 用户远程登录。输入 Y 并按 Enter。

步骤 6:删除测试数据库

删除默认安装的测试数据库,它可以被任何用户访问。输入 Y 并按 Enter。

步骤 7:重新加载权限表

最后,重新加载权限表,以确保所有更改生效。输入 Y 并按 Enter。

完整示例

以下是一个完整的示例输出:

Securing the MySQL server deployment.

Enter password for user root: (输入当前的 root 密码或直接按 Enter 如果没有密码)

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

New password: (输入新的 root 密码)

Re-enter new password: (重新输入新的 root 密码)

VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security.

It checks the strength of password and allows the users to set only those passwords which are secure enough.

Would you like to setup VALIDATE PASSWORD plugin

Press y|Y for Yes, any other key for No: Y (根据需要选择是否启用密码验证插件)

Please set the password validation policy:

LOW Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 (选择密码验证策略)

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) : N (如果刚刚设置了密码,这里选择 N)

... skipping.

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 (禁止 root 用户远程登录)

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!

你已经成功执行了 mysql_secure_installation 并提高了 MySQL 服务器的安全性。

相关推荐
跨境生态圈1 分钟前
2026谷歌SEO快速排名深度解析:合规起量、避坑指南与实战落地策略
数据库·人工智能·爬虫·搜索引擎·chatgpt
JavaPub-rodert28 分钟前
Docker 安装 MySQL 完整教程:从零部署数据库,到生产环境持久化配置
数据库·mysql·docker
隔窗听雨眠42 分钟前
MySQL整库迁移至KaiwuDB完全指南:从数据类型映射到生产切换的系统性实践
数据库·mysql
xhbh6661 小时前
中小企业 Redis 运维,如何安全归档 RDB、AOF 备份文件?
运维·数据库·缓存·数据备份·文件备份·同步备份·号码备份
我不是程序员三三1 小时前
内网监控系统|终端监控上线验收与常态化安全自查清单
安全
2301_32241428041 小时前
活力孕康复APP 47737- 原创(免费领源码+部署教程+开发环境)
java·vue.js·spring boot·mysql·微信小程序·idea·微信开发者工具
勤奋的树懒1 小时前
从手写 SQL 到 Windows 工具:致远 OA 文件清理实践
数据库·sql·windows server·致远oa
笃行3501 小时前
OceanBaseVS金仓:一条 SQL 的两条路——KingbaseES 的性能竞争力从哪来
数据库
其实防守也摸鱼2 小时前
每天一个知识点——RCE漏洞
运维·服务器·数据库·windows·安全·github·漏洞
TDengine (老段)2 小时前
TDengine 常见问题 TOP2
大数据·数据库·物联网·时序数据库·tdengine·涛思数据