Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

MysqlLinuxRhelRhel5

Mysql Problem Overview


I am on a server that has afresh install on RHEL 5. I was able to install Apache and PHP just fine., but I am having serious trouble with my MySQL installation. I tried the following:

yum install mysql-server mysql 

And didn't get any errors or conflicts. Then I tried to start mysql with the following commands:

chkconfig --levels 235 mysqld on
service mysqld start

And get Timeout error occurred trying to start MySQL Daemon.

I checked my logs and see this error:

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

I'm not sure where to go from here.

For reference I am using RHEL 5 and installed the latest versions of PHP 5 and Apache.

Mysql Solutions


Solution 1 - Mysql

After chown and chgrp'ing /var/lib/mysql per the answer by @Bad Programmer, you may also have to execute the following command:

sudo mysql_install_db --user=mysql --ldata=/var/lib/mysql

Then restart your mysqld.

Solution 2 - Mysql

  1. Uninstall mysql using yum remove mysql*

  2. Recursively delete /usr/bin/mysql and /var/lib/mysql

  3. Delete the file /etc/my.cnf.rmp

  4. Use ps -e to check the processes to make sure mysql isn't still running.

  5. Reboot server with reboot

  6. Run yum install mysql-server. This also seems to install the mysql client as a dependency.

  7. Give mysql ownership and group priveleges with:

    chown -R mysql /var/lib/mysql

    chgrp -R mysql /var/lib/mysql

  8. Use service mysqld start to start MySQL Daemon.

Solution 3 - Mysql

I had this issue on arch linux as well. The issue was pacman installed the package in a different location than MySQL was expecting. I was able to fix the issue with this:

sudo mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/

Hope this helps someone!

Solution 4 - Mysql

The root of my problem seemed to be selinux, which was turned on (enforcing) automatically on OS install.

I wanted my mysql in /data.

After verifying that my.cnf had:

datadir=/data/mysql

(and leaving the socket at /var/lib/mysql) I executed the command to turn off selinux for mysqld (alternative is to turn it off completely):

setsebool -P mysqld_disable_trans=1

I ran the following commands:

> chown -R mysql .
> chgrp -R mysql .
> mysql_install_db --user=mysql

I started the mysql daemon and everything worked fine after that.

Solution 5 - Mysql

mysql_install_db –-user=mysql --ldata=/var/lib/mysql

Worked for me in Centos 7

Solution 6 - Mysql

initialize mysql before start on windows.

mysqld --initialize

Solution 7 - Mysql

When download mysql zip version, if run mysqld directly, you'll get this error: 2016-02-18T07:23:48.318481Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 2016-02-18T07:23:48.319482Z 0 [ERROR] Aborting

You have to run below command first: mysqld --initialize

Make sure your data folder is empty before this command.

Solution 8 - Mysql

I just met the same problem with mysql 5.7 on OSX:

rm -rf {datadir}
mysqld --initialize --datadir {datadir}
mysqld --datadir {datadir}

Solution 9 - Mysql

If you move your datadir, you not only need to give the new datadir permissions, but you need to ensure all parent directories have permission.

I moved my datadir to a hard drive, mounted in Ubuntu as:

/media/*user*/Data/

and my datadir was Databases.

I had to set permissions to 771 to each of the media, user and Data directories:

sudo chmod 771 *DIR*

If this does not work, another way you can get mysql to work is to change user in /etc/mysql/my.cnf to root; though there are no doubt some issues with doing that from a security perspective.

Solution 10 - Mysql

Just this command is enough to do the magic on centos 6.6

mysql_install_db

Solution 11 - Mysql

For myself, I had to do:

yum remove mysql*

rm -rf /var/lib/mysql/
cp /etc/my.cnf ~/my.cnf.bkup

yum install -y mysql-server mysql-client

mysql_install_db

chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /var/log/mysql

service mysql start

Then I was able to get back into my databases and configure them again after I nuked them the first go around.

Solution 12 - Mysql

In my case the path of MySQL data folder had a special character "ç" and it make me get...

> Fatal error: Can't open and lock privilege tables: Table 'mysql.host' > doesn't exist.

I'm have removed all special characters and everything works.

Solution 13 - Mysql

On CentOS EL 6 and perhaps on earlier versions there is one way to get into this same mess.

Install CentOS EL6 with a minimal installation. For example I used kickstart to install the following:

%packages
@core
acpid
bison
cmake
dhcp-common
flex
gcc
gcc-c++
git
libaio-devel
make
man
ncurses-devel
perl
ntp
ntpdate
pciutils
tar
tcpdump
wget
%end

You will find that one of the dependencies of the above list is mysql-libs. I found that my system has a default my.cnf in /etc and this contains:

[mysqld]
dataddir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

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

When you build from the Generic Linux (Architecture Independent), Compressed TAR Archive your default data directory is /usr/local/mysql/data which conflicts with the /etc/my.cnf already present which defines datadir=/var/lib/mysql. Also the pid-file defined in the same file does not have permissions for the mysql user/group to write to it in /var/run/mysqld.

A quick remedy is to mv /etc/my.cnf /etc/my.cnf.old which should get your generic source procedure working.

Of course the experience is different of you use the source RPMs.

Solution 14 - Mysql

I had the same issue in trying to start the server and followed the "checked" solution. But still had the problem. The issue was the my /etc/my.cnf file was not pointing to my designated datadir as defined when I executed the mysql_install_db with --datadir defined. Once I updated this, the server started correctly.

Solution 15 - Mysql

If you have a server which used to happily run MySQL, but now gives this error, then an uninstall and re-install of MySQL is overkill.

In my case, the server died and took a few disk blocks with it. This affected a few files, including /var/lib/mysql/mysql/host.frm and /var/lib/mysql/mysql/proc.frm

Luckily, I could copy these from another server, and this got me past that table error.

Solution 16 - Mysql

I got similar error on overlayfs (overlay2) that is the default on Docker for Mac. The error happens when starting mysql on the image, after creating a image with mysql.

2017-11-15T06:44:22.141481Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option

Switching to "aufs" solved the issue. (On Docker for Mac, the "daemon.json" can be edited by choosing "Preferences..." menu, and selecting "Daemon" tab, and selecting "Advanced" tab.)

/etc/docker/daemon.json :

{
  "storage-driver" : "aufs",
  "debug" : true,
  "experimental" : true
}

Ref:

https://github.com/moby/moby/issues/35503

https://qiita.com/Hige-Moja/items/7b1208f16997e2aa9028

Solution 17 - Mysql

In Windows run the following commands in the command prompt as adminstrator

Step 1:
mysql_install_db.exe

Step 2:
mysqld --initialize

Step 3:
mysqld --console

Step 4:
In windows

Step 4:
mysqladmin -u root password "XXXXXXX"

Step 5:
mysql -u root -p

Mariadb database information

Solution 18 - Mysql

My case on Ubuntu 14.04.2 LTS was similar to others with my.cnf, but for me the cause was a ~/.my.cnf that was leftover from a previous installation. After deleting that file and purging/re-installing mysql-server, it worked fine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBad ProgrammerView Question on Stackoverflow
Solution 1 - Mysqlbk0View Answer on Stackoverflow
Solution 2 - MysqlBad ProgrammerView Answer on Stackoverflow
Solution 3 - MysqlzomblakeView Answer on Stackoverflow
Solution 4 - MysqlIlaneView Answer on Stackoverflow
Solution 5 - MysqlJVJView Answer on Stackoverflow
Solution 6 - MysqltvrcgoView Answer on Stackoverflow
Solution 7 - MysqlLevinView Answer on Stackoverflow
Solution 8 - MysqlShuoView Answer on Stackoverflow
Solution 9 - MysqlKohjah BreeseView Answer on Stackoverflow
Solution 10 - Mysqlvenkat samView Answer on Stackoverflow
Solution 11 - MysqlFilBot3View Answer on Stackoverflow
Solution 12 - MysqlFelipe LoredoView Answer on Stackoverflow
Solution 13 - MysqlChris LabonneView Answer on Stackoverflow
Solution 14 - MysqlzagatztuView Answer on Stackoverflow
Solution 15 - MysqlNigel PearsonView Answer on Stackoverflow
Solution 16 - MysqlTsuneo YoshiokaView Answer on Stackoverflow
Solution 17 - MysqlAshraff Ali WahabView Answer on Stackoverflow
Solution 18 - MysqlejaView Answer on Stackoverflow