1、安装
#sudo yum install -y mysql-server
2、初始化
#sudo mysqld --initialize --user=mysql --lower-case-table-names=1
这个很关键、如果没有初始化时设置lower-case-table-names=1后面在my.cnf文件修改将无法启动mysql
3、启动MySQL服务
#systemctl start mysqld
4、登录mysql
#sudo mysql
如果出现:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
这个错误,需要处理密码。
处理办法:
4.1、修改my.cnf
#vim /etc/my.cnf
可以看到centos8上的mysql配置文件已经改变,进入:/etc/my.cnf.d
服务端的配置文件为:/etc/my.cnf.d/mysql-server.cnf
#vim /etc/my.cnf.d/mysql-server.cnf
在[mysqld]下面加上:skip-grant-tables 保存退出
4.2、免密码登录、然后修改配置
#sudo mysql
mysql>use mysql
mysql>update user set plugin='mysql_native_password' where User='root';
mysql>update user set authentication_string='' where user='root';
mysql>exit
4.3、删除或注释skip-grant-tables
4.4、重启登录修改新密码
#systemctl restart mysqld
#sudo mysql
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY '新密码';
mysql>flush privileges;
mysql>exit
4.5、用新密码登录
#mysql -uroot -p新密码
mysql>
5、设置mysql服务自启动
#systemctl enable mysqld
重启系统
#systemctl status mysqld
服务正常启动。