centos7使用 yum 安装mysql教程

我忽然发现,使用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

至此,解决了所有问题!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值