Rocky8.6安装MySQL

578 阅读2分钟

  经朋友推荐,我接触了Rocky Linux,不得不说,Rocky Linux真的舒服,本人目前使用的是Rocky8.6。

  本篇讲一下安装MySQL

1. 安装MySQL

sudo dnf install -y @mysql # 目测Rocky9不能通过此方式安装MySQL

2. 启动服务

sudo systemctl start mysqld

sudo systemctl enable mysqld

3. 运行初始化脚本

sudo mysql_secure_installation

注意下有注释的地方就可以

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?# 是否要设置valid password组件?

Press y|Y for Yes, any other key for No: n  # 输入一个非y或Y的字符。

Please set the password for root here.

New password:  # 输入MySQL的密码,我这里输入的是123456

Re-enter new password:  # 再次输入MySQL的密码
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 # 从此处开始,后续都是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!

4. 登陆MySQL

mysql -uroot -p123456 # 进入数据库

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.26 Source distribution

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> 

此时已经进入了MySQL,我们只需要检查一下MySQL是否允许远程连接就可以了

use mysql;
select user,host from user;# 查看当前mysql的用户及权限

# 初始化脚本中选择的是不允许远程登录MySQL,所以我是需要修改权限的
update user set host='%' where user='root';
flush privileges;# 刷新权限表

至此,MySQL就能正常使用了。总的来说Rocky的这种方式安装MySQL其实挺好的(也不知道为什么Rocky9不支持),至少安装、配置简单了很多