centos7 yum安装mysql后启动不起来问题

时间:2021-06-07 20:34:38

[root@localhost ~]# systemctl start mysqld       启动失败

Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

查看系统日志报错为:

May 29 19:04:53 localhost mysqld: 2018-05-29T11:04:53.723812Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
May 29 19:04:53 localhost mysqld: 2018-05-29T11:04:53.723862Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
May 29 19:04:53 localhost mysqld: 2018-05-29T11:04:53.723871Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
May 29 19:04:54 localhost mysqld: 2018-05-29T11:04:54.325440Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
May 29 19:04:54 localhost mysqld: 2018-05-29T11:04:54.325475Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
May 29 19:04:54 localhost mysqld: 2018-05-29T11:04:54.325483Z 0 [ERROR] Failed to initialize builtin plugins.
May 29 19:04:54 localhost mysqld: 2018-05-29T11:04:54.325485Z 0 [ERROR] Aborting

报错原因大致为:你的数据文件不可写

导致原因:yum安装的mysql的拥有者是root,而mysql要求执行身份为mysql,权限问题导致数据文件不可写

  解决方法如下:

[root@localhost ~]# chown -R mysql /var/lib/mysql

[root@localhost ~]# systemctl start mysqld

[root@localhost ~]# tailf /var/log/messages &

日志打印:

May 29 19:09:15 localhost mysqld: Version: '5.7.22'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

启动成功

登录 MySQL,此时不需要密码,直接回车:

# mysql -u root -p

更改 root 密码 为 123456

mysql> use mysql;
mysql> update user set authentication_string=password("123456") where user='root';
mysql> flush privileges; # 刷新权限,不刷新的话可能导致mysql回车直接就会登录

注意密码字段名 5.7 版本的是 authentication_string,之前的为 password

修改完后,记得注释掉 my.cnf 中的 skip-grant-tables 参数,重启 MySQL 服务,就可以用你设置的密码登录了。