MySQL [ERROR] Table 'mysql.user' doesn't exist

时间:2022-09-20 08:30:23

问题描述:

在安装MYsql时,/etc/init.d/mysqld start时报错:

[root@master data]# /etc/init.d/mysqld start
Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/master.pid).

解决步骤:

1、检查安装MYSQL时的脚本,及指定的文件

2、查看mariadb.log发现相关错误:

[root@master init.d]# cd /var/log/mariadb
[root@master mariadb]# ls
mariadb.log

MySQL [ERROR] Table 'mysql.user' doesn't exist

具体错误为:[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist。下面是该错误的描述及其解决办法。

#查看当前的my.cnf配置文件

[root@master mariadb]#  more /etc/my.cnf |grep -v ^#
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d

#由于编译安装时指定的路径为/mnt/mysql/data以及mysql_install_db时指定的datadir也为/mnt/mysql/data:

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mnt/mysql/data --user=mysql

而my.cnf为指定的路径为

/var/lib/mysql

#因此修改datadir至正确路径:

[root@master mariadb]#  more /etc/my.cnf |grep -v ^#
[mysqld]
datadir=/mnt/mysql/data
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d

[root@master mariadb]# service mysqld start
Starting MySQL. SUCCESS!