服务器安装mysql8.0
安装
安装MySQL及其所有依赖
sudo dnf install @mysql
启动MySQL服务,并设置自启
sudo systemctl enable --now mysqld
检查MySQL服务器是否正在运行
sudo systemctl status mysqld
运行mysql_secure_installation脚本,该脚本执行一些与安全性相关的操作并设置MySQL根密码:
sudo mysql_secure_installation
配置
- 配置VALIDATE PASSWORD component(验证密码组件): 输入y ,回车进入该配置
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: y
- 选择密码验证策略等级, 这里选择0 (low),回车
There 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 file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
输入新密码两次(mysql -u root -p 回车时输的密码)
确认是否继续使用提供的密码?输入y ,回车
移除匿名用户? 输入y,回车
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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.
- 不允许root远程登陆? 需要远程登陆,所以输入n ,回车
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) : n
- 移除test数据库? 输入y ,回车
- 重新载入权限表? 输入y ,回车
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 -u root -p
退出
exit;
卸载
移除mariadb程序文件
yum remove -y mariadb*
查询mysql相关文件并删
find / -name "mysql*" |xargs rm -rf
find / -name "mariadb*" |xargs rm -rf
附:终端信息
[root@iZbp1gp1t778o6paja9tabZ ~]# sudo dnf install @mysql
上次元数据过期检查:0:58:50 前,执行于 2021年02月25日 星期四 21时38分48秒。
依赖关系解决。
===============================================================================================================================
软件包 架构 版本 仓库 大小
===============================================================================================================================
安装组/模块包:
mysql-server x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 appstream 22 M
安装依赖关系:
mariadb-connector-c-config noarch 3.1.11-2.el8_3 appstream 15 k
mecab x86_64 0.996-1.module_el8.2.0+493+63b41e36.9 appstream 393 k
mysql x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 appstream 12 M
mysql-common x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 appstream 148 k
mysql-errmsg x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 appstream 581 k
protobuf-lite x86_64 3.5.0-13.el8 appstream 149 k
安装模块配置档案:
mysql/server
启用模块流:
mysql 8.0
事务概要
===============================================================================================================================
安装 7 软件包
总下载:35 M
安装大小:182 M
确定吗?[y/N]: y
下载软件包:
(1/7): mariadb-connector-c-config-3.1.11-2.el8_3.noarch.rpm 116 kB/s | 15 kB 00:00
(2/7): mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64.rpm 1.7 MB/s | 393 kB 00:00
(3/7): mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64.rpm 1.4 MB/s | 148 kB 00:00
(4/7): mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64.rpm 1.2 MB/s | 581 kB 00:00
(5/7): protobuf-lite-3.5.0-13.el8.x86_64.rpm 4.0 MB/s | 149 kB 00:00
(6/7): mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64.rpm 5.8 MB/s | 12 MB 00:02
(7/7): mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64.rpm 11 MB/s | 22 MB 00:02
-------------------------------------------------------------------------------------------------------------------------------
总计 12 MB/s | 35 MB 00:03
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 1/7
安装 : mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 2/7
安装 : mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 3/7
安装 : mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 4/7
安装 : protobuf-lite-3.5.0-13.el8.x86_64 5/7
安装 : mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 6/7
运行脚本: mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 6/7
运行脚本: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 7/7
安装 : mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 7/7
运行脚本: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 7/7
ValueError: /var/log/mysql(/.*)? 的文件上下文已定义
验证 : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 1/7
验证 : mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 2/7
验证 : mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 3/7
验证 : mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 4/7
验证 : mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 5/7
验证 : mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 6/7
验证 : protobuf-lite-3.5.0-13.el8.x86_64 7/7
已安装:
mariadb-connector-c-config-3.1.11-2.el8_3.noarch mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64
mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
protobuf-lite-3.5.0-13.el8.x86_64
完毕!
[root@iZbp1gp1t778o6paja9tabZ ~]# sudo systemctl status mysql
● mysql.service
Loaded: not-found (Reason: Unit mysql.service not found.)
Active: failed (Result: exit-code) since Thu 2021-02-25 22:32:38 CST; 5min ago
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: Starting MySQL Community Server...
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: mysql.service: Control process exited, code=exited status=203
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: mysql.service: Failed with result 'exit-code'.
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: Failed to start MySQL Community Server.
[root@iZbp1gp1t778o6paja9tabZ ~]# sudo systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@iZbp1gp1t778o6paja9tabZ ~]# sudo systemctl status mysql
● mysql.service
Loaded: not-found (Reason: Unit mysql.service not found.)
Active: failed (Result: exit-code) since Thu 2021-02-25 22:32:38 CST; 6min ago
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: Starting MySQL Community Server...
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: mysql.service: Control process exited, code=exited status=203
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: mysql.service: Failed with result 'exit-code'.
2月 25 22:32:38 iZbp1gp1t778o6paja9tabZ systemd[1]: Failed to start MySQL Community Server.
[root@iZbp1gp1t778o6paja9tabZ ~]# mysql -v
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Reading history-file /root/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit;
Writing history-file /root/.mysql_history
Bye
[root@iZbp1gp1t778o6paja9tabZ ~]# 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?
Press y|Y for Yes, any other key for No: y
There 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 file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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) : n
... skipping.
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@iZbp1gp1t778o6paja9tabZ ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.21 Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>