我忽然发现,使用centos7安装MySQL时,安装的是mariadb,而且无法启动MySQL,报错。主要有
Failed to start mariadb.service: Unit not found.
Failed to start mysql.service: Unit not found.
mysql有版本信息返回,无法登录。
解决方案:
1.安装mysql
yum -y install mysql mariadb-server
2.修改my.cnf文件‘
vim /etc/my.cnf
在[mysqld] 下加上一句skip-grant-tables
例如,原配置文件为:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
修改后为
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
skip-grant-tables
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
3.重启服务
systemctl restart mariadb
如果这一步失败,说明安装有了问题。
4.登录mysql,修改密码
执行命令
mysql-u root -p
提示输入密码,直接回车。
修改密码
flush privileges;
set password for root@localhost = password("你想设置的root密码");
例如:
flush privileges;
set password for root@localhost = password("1");
5.退出,修改回my.cnf文件
exit;
vim /etc/my.cnf
把刚才加的那句skip-grant-tables删除掉,保存。重启MariaDB服务
systemctl restart mariadb
至此,解决了所有问题!