欧拉服务器操作系统安装MySQL
1. 安装MySQL服务器
更新仓库缓存
sudo dnf makecache
安装MySQL
sudo dnf install mysql-server
2. 初始化数据库
sudo mysqld --initialize --user=mysql
3. 启动数据库服务
# 启动服务
sudo systemctl start mysqld# 设置开机自启
sudo systemctl enable mysqld# 检查状态
sudo systemctl status mysqld
4. 获取初始临时密码
MySQL首次启动后会生成临时root密码:
[root@koji-builder local]# cat /var/log/mysql/mysqld.log
2025-04-15T03:47:19.698504Z 0 [System] [MY-013169] [Server] /usr/libexec/mysqld (mysqld 8.0.26) initializing of server in progress as process 501966
2025-04-15T03:47:19.707644Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-15T03:47:20.097607Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-15T03:47:21.185380Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2025-04-15T03:47:21.185792Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2025-04-15T03:47:21.335996Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2025-04-15T03:47:24.352442Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.26) starting as process 502015
2025-04-15T03:47:24.360719Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-15T03:47:24.454276Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-15T03:47:24.663767Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2025-04-15T03:47:24.664110Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2025-04-15T03:47:24.666148Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2025-04-15T03:47:24.666287Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2025-04-15T03:47:24.683037Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/lib/mysql/mysqlx.sock
2025-04-15T03:47:24.683165Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.26' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution.
2025-04-15T03:50:47.632895Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.26).
2025-04-15T03:50:48.933911Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.26) Source distribution.
2025-04-15T03:51:01.921293Z 0 [System] [MY-013169] [Server] /usr/libexec/mysqld (mysqld 8.0.26) initializing of server in progress as process 502402
2025-04-15T03:51:01.937221Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-15T03:51:02.314323Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-15T03:51:03.280084Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2025-04-15T03:51:03.280364Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2025-04-15T03:51:03.328444Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: V8xP0pUmup?J
5. 使用临时密码登录
[root@koji-builder local]# mysql -u root -p'V8xP0pUmup?J'
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.26Copyright (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>
6. 首次登录后强制修改密码
修改 root 密码(需满足复杂度要求,如大小写字母、数字、符号)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yuhua@24';
Query OK, 0 rows affected (0.00 sec)
7. 运行安全加固脚本
[root@koji-builder local]# sudo mysql_secure_installation Securing the MySQL server deployment.Enter password for user root: 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?Press y|Y for Yes, any other key for No: yThere are three levels of 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 filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 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
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 密码。
移除匿名用户(选 Y)。
禁止远程 root 登录(选 Y)。
删除测试数据库(选 Y)。
刷新权限表(选 Y)。
8. 登录数据库
[root@koji-builder local]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26 Source distributionCopyright (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>