CentOS 8 软件库中内置了MySQL 8,安装较CentOS 7 方便许多。
1、首先切换用户为root用户或者sudo特权用户执行下面的命令安装MySQL及其依赖
dnf install @mysql
2、安装完成后,启动mysql
systemctl enable --now mysqld
3、启动成功查看mysql状态
systemctl status mysqld
4、运行mysql_secure_installation脚本
[root@localhost ~]# mysql_secure_installation
(1)首先会提示你配置验证密码插件,这里可以不选择直接Enter
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:
(2)提示你设置root密码,设置一个密码即可
Please set the password for root here.
(3)提示你是否删除匿名用户
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.
(4)提示你是否禁止root用户远程登录
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.
(5)提示你是否删除测试数据库
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
(6)提示你是否重新加载授权信息
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
5、配置完成后使用设置的密码登录mysql