当前位置: 首页 > news >正文

欧拉服务器操作系统安装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>

相关文章:

  • Ollama、vLLM、LMDeploy选型指南
  • 什么是ETF跟踪误差?场内基金佣金最低是多少?
  • 批量将不同位置的多个文件复制到一个文件夹
  • Oracle查询大表的全部数据
  • JDBC 初认识、速了解
  • 谷云科技iPaaS集成平台4月发布新版本V7.4
  • 谷歌发布统一安全平台:让企业安全防护更简单
  • Spring如何解决项目中的循环依赖问题?
  • AI日报 - 2025年04月16日
  • 10 穴 汽车连接器的15个设计特点
  • 【AGI】MCP生态的“飞轮效应”
  • [随笔杂谈] 计算机编程 —— 通用学习等级体系
  • 数据库—函数笔记
  • 智慧声防:构筑海滨浴场安全屏障的应急广播系
  • 设计和实现一个基于 DDS(直接数字频率合成) 的波形发生器
  • WPF静态资源StaticResource和动态资源DynamicResource有什么区别,x:Static又是什么意思?
  • 在Android Studio中,`Settings`里的Gradle路径、环境变量以及`gradle - wrapper.properties`文件关联
  • 【面向对象设计C++--翁恺】05-时钟例子+06-成员变量+07-构造和析构+08-对象初始化
  • 2025年最新图像生成模型调研报告
  • 大模型Qwen32b(FP16精度)部署所需的显存大小和并发数计算分析
  • 王毅同伊朗外长阿拉格齐会谈
  • 赵志丹任中国地质大学(北京)校长
  • 上海一小学百名学生齐聚图书馆:纸质书的浪漫AI无法取代
  • 山西公布商标侵权典型案例:一工厂生产价值三百多万假“维达”纸被查
  • 史蒂夫·麦奎因透露罹患前列腺癌,呼吁同胞莫受困于男性气概
  • 市场监管部门完成全国保健食品生产企业体系检查首轮全覆盖