简体   繁体   English

致命错误:无法打开和锁定权限表:表 'mysql.host' 不存在

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

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.我在一台在 RHEL 5 上重新安装的服务器上。我能够很好地安装 Apache 和 PHP。但是我的 MySQL 安装遇到了严重的问题。 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:然后我尝试使用以下命令启动 mysql:

chkconfig --levels 235 mysqld on
service mysqld start

And get Timeout error occurred trying to start MySQL Daemon.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.作为参考,我使用 RHEL 5 并安装了最新版本的 PHP 5 和 Apache。

After chown and chgrp 'ing /var/lib/mysql per the answer by @Bad Programmer , you may also have to execute the following command:根据@Bad Programmer的回答chownchgrp 'ing /var/lib/mysql之后,您可能还必须执行以下命令:

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

Then restart your mysqld .然后重启你的mysqld

  1. Uninstall mysql using yum remove mysql*使用yum remove mysql*卸载 mysql

  2. Recursively delete /usr/bin/mysql and /var/lib/mysql递归删除/usr/bin/mysql/var/lib/mysql

  3. Delete the file /etc/my.cnf.rmp删除文件/etc/my.cnf.rmp

  4. Use ps -e to check the processes to make sure mysql isn't still running.使用ps -e检查进程以确保 mysql 未仍在运行。

  5. Reboot server with reboot与重启服务器reboot

  6. Run yum install mysql-server .运行yum install mysql-server This also seems to install the mysql client as a dependency.这似乎也将 mysql 客户端安装为依赖项。

  7. Give mysql ownership and group priveleges with:授予 mysql 所有权和组特权:

    chown -R mysql /var/lib/mysql

    chgrp -R mysql /var/lib/mysql

  8. Use service mysqld start to start MySQL Daemon.使用service mysqld start启动 MySQL Daemon。

I had this issue on arch linux as well.我在 arch linux 上也有这个问题。 The issue was pacman installed the package in a different location than MySQL was expecting.问题是 pacman 将软件包安装在与 MySQL 预期不同的位置。 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!希望这可以帮助某人!

The root of my problem seemed to be selinux, which was turned on (enforcing) automatically on OS install.我的问题的根源似乎是 selinux,它在操作系统安装时自动打开(强制执行)。

I wanted my mysql in /data.我希望我的 mysql 在 /data 中。

After verifying that my.cnf had:在验证 my.cnf 有:

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): (并将套接字留在 /var/lib/mysql)我执行了关闭 mysqld 的 selinux 的命令(另一种方法是将其完全关闭):

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.我启动了 mysql 守护进程,之后一切正常。

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

在 Centos 7 为我工作

在 Windows 上启动之前初始化 mysql。

mysqld --initialize

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下载mysql zip版本时,如果直接运行mysqld,会报错:2016-02-18T07:23:48.318481Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user'不存在 2016-02-18T07:23:48.319482Z 0 [错误] 中止

You have to run below command first: mysqld --initialize您必须首先运行以下命令:mysqld --initialize

Make sure your data folder is empty before this command.在执行此命令之前,请确保您的数据文件夹为空。

I just met the same problem with mysql 5.7 on OSX:我刚刚在 OSX 上使用 mysql 5.7 遇到了同样的问题:

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

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.如果移动 datadir,不仅需要赋予新的 datadir 权限,还需要确保所有父目录都有权限。

I moved my datadir to a hard drive, mounted in Ubuntu as:我将我的 datadir 移动到硬盘驱动器,安装在 Ubuntu 中:

/media/*user*/Data/

and my datadir was Databases .我的 datadir 是Databases

I had to set permissions to 771 to each of the media, user and Data directories:我必须将每个媒体、用户和数据目录的权限设置为 771:

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;如果这不起作用,另一种让 mysql 工作的方法是将 /etc/mysql/my.cnf 中的用户更改为 root; though there are no doubt some issues with doing that from a security perspective.尽管从安全角度来看,这样做无疑存在一些问题。

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.然后我能够回到我的数据库并在我第一次使用它们之后再次配置它们。

Just this command is enough to do the magic on centos 6.6仅此命令就足以在 centos 6.6 上施展魔法

mysql_install_db mysql_install_db

In my case the path of MySQL data folder had a special character "ç" and it make me get...在我的情况下,MySQL 数据文件夹的路径有一个特殊字符“ç”,它让我得到...

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist.致命错误:无法打开和锁定权限表:表 'mysql.host' 不存在。

I'm have removed all special characters and everything works.我已经删除了所有特殊字符,一切正常。

On CentOS EL 6 and perhaps on earlier versions there is one way to get into this same mess.在 CentOS EL 6 上,也许在更早的版本上,有一种方法会陷入同样的​​混乱。

Install CentOS EL6 with a minimal installation.以最小安装方式安装 CentOS EL6。 For example I used kickstart to install the following:例如,我使用 kickstart 安装以下内容:

%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 .您会发现上述列表的依赖项之一是mysql-libs I found that my system has a default my.cnf in /etc and this contains:我发现我的系统在/etc有一个默认的my.cnf ,它包含:

[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 .当您从Generic Linux (Architecture Independent), Compressed TAR Archive构建时,您的默认数据目录是/usr/local/mysql/data ,它与已存在的/etc/my.cnf冲突,后者定义了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 .此外,在同一文件中定义的pid-file文件没有 mysql 用户/组在/var/run/mysqld写入的权限。

A quick remedy is to mv /etc/my.cnf /etc/my.cnf.old which should get your generic source procedure working.一个快速的补救方法是mv /etc/my.cnf /etc/my.cnf.old这应该让你的通用源程序工作。

Of course the experience is different of you use the source RPMs.当然,使用源 RPM 的体验是不同的。

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.问题是我的 /etc/my.cnf 文件没有指向我在定义 --datadir 的情况下执行 mysql_install_db 时定义的指定数据目录。 Once I updated this, the server started correctly.一旦我更新了这个,服务器就正确启动了。

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.如果您的服务器曾经可以愉快地运行 MySQL,但现在出现此错误,那么卸载并重新安装 MySQL 是多余的。

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这影响了一些文件,包括 /var/lib/mysql/mysql/host.frm 和 /var/lib/mysql/mysql/proc.frm

Luckily, I could copy these from another server, and this got me past that table error.幸运的是,我可以从另一台服务器复制这些,这让我克服了那个表错误。

I got similar error on overlayfs (overlay2) that is the default on Docker for Mac.我在overlayfs(overlay2)上遇到了类似的错误,这是Docker for Mac的默认设置。 The error happens when starting mysql on the image, after creating a image with mysql.使用 mysql 创建映像后,在映像上启动 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.切换到“aufs”解决了这个问题。 (On Docker for Mac, the "daemon.json" can be edited by choosing "Preferences..." menu, and selecting "Daemon" tab, and selecting "Advanced" tab.) (在 Docker for Mac 上,“daemon.json”可以通过选择“Preferences...”菜单,然后选择“Daemon”选项卡,然后选择“Advanced”选项卡来编辑。)

/etc/docker/daemon.json : /etc/docker/daemon.json :

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

Ref:参考:

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

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

In Windows run the following commands in the command prompt as adminstrator在 Windows 中,以管理员身份在命令提示符下运行以下命令

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 数据库信息

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.我在 Ubuntu 14.04.2 LTS 上的情况与 my.cnf 上的其他情况类似,但对我而言,原因是之前安装遗留的 ~/.my.cnf。 After deleting that file and purging/re-installing mysql-server, it worked fine.删除该文件并清除/重新安装 mysql-server 后,它运行良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 移动数据后无法运行mysql(严重错误:无法打开和锁定特权表:表'mysql.host'不存在) - Cannot run mysql after moving data (Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist) Mysql/mariadb“无法打开和锁定权限表:表‘mysql.servers’不存在” - Mysql/mariadb "Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist" Docker中的Bootstraping Percona Xtradb Cluster出现错误:无法打开和锁定特权表:表'mysql.user'不存在 - Bootstraping Percona Xtradb Cluster in Docker gives the error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 无法打开和锁定权限表:表 'mysql.user' 不存在 - Can't open and lock privilege tables: Table 'mysql.user' doesn't exist MySQL致命错误:无法打开和锁定权限表:文件格式“用户”不正确 - MySQL Fatal error: Can't open and lock privilege tables: Incorrect file format 'user' Mysql给我:“无法打开和锁定特权表:表'主机'是只读的” - Mysql gives me:“Can't open and lock privilege tables: Table 'host' is read only” 如何修复致命错误:无法打开和锁定特权表:表 '.\mysql\proxies_priv' 被标记为已崩溃并且最后(自动?)修复失败 - How do I fix Fatal error: Can't open and lock privilege tables: Table '.\mysql\proxies_priv' is marked as crashed and last (automatic?) repair failed 服务mysql启动在我的日志文件中留下“特权表:表'mysql.user'不存在”并且服务器失败 - service mysql start leaves “privilege tables: Table 'mysql.user' doesn't exist” in my log file and the server fails mysqldump: Got error: 1146: Table 'myDatabase.table' 在使用 LOCK TABLES 时不存在 - mysqldump: Got error: 1146: Table ' myDatabase.table' doesn't exist when using LOCK TABLES MySQL表“不存在”错误 - MySQL table “doesn't exist” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM