致命错误:无法打开和锁定权限表:表“mysql.host”;不存在
我所在的服务器在 RHEL 5 上重新安装。我能够很好地安装 Apache 和 PHP,但是我在安装 MySQL 时遇到了严重问题。我尝试了以下操作:
yum install mysql-server mysql
并且没有收到任何错误或冲突。然后我尝试使用以下命令启动 mysql:
chkconfig --levels 235 mysqld on
service mysqld start
并得到 尝试启动 MySQL Daemon 时发生超时错误。
我检查了日志并看到此错误:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
我不确定从这里去哪里。
作为参考,我使用 RHEL 5 并安装了最新版本的 PHP 5 和 Apache。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
对于我自己来说,我必须这样做:
然后我能够回到我的数据库并在我第一次攻击它们后再次配置它们。
For myself, I had to do:
Then I was able to get back into my databases and configure them again after I nuked them the first go around.
在 Windows 中,以管理员身份在命令提示符下运行以下命令
In Windows run the following commands in the command prompt as adminstrator
就我而言,MySQL 数据文件夹的路径有一个特殊字符“ç”,它让我得到......
我已经删除了所有特殊字符并且一切正常。
In my case the path of MySQL data folder had a special character "ç" and it make me get...
I'm have removed all special characters and everything works.
在 CentOS EL 6 甚至更早的版本上,有一种方法可以解决同样的问题。
使用最小安装安装 CentOS EL6。例如,我使用kickstart来安装以下内容:
您会发现上面列表的依赖项之一是
mysql-libs
。我发现我的系统在/etc
中有一个默认的my.cnf
,其中包含:当您从
Generic Linux(架构独立)构建时,压缩的 TAR 存档
你的默认数据目录是/usr/local/mysql/data
,它与已经存在的定义datadir= 的
。此外,同一文件中定义的 pid-file 没有 mysql 用户/组在/etc/my.cnf
冲突/var/lib/mysql/var/run/mysqld
中写入的权限。一个快速的补救措施是
mv /etc/my.cnf /etc/my.cnf.old
这应该让您的通用源程序正常工作。当然,使用源 RPM 的体验是不同的。
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:
You will find that one of the dependencies of the above list is
mysql-libs
. I found that my system has a defaultmy.cnf
in/etc
and this contains: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 definesdatadir=/var/lib/mysql
. Also thepid-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.
我在尝试启动服务器时遇到了同样的问题,并遵循“已检查”的解决方案。
但仍然有问题。问题是我的 /etc/my.cnf 文件没有指向我的
当我执行 mysql_install_db 并定义了 --datadir 时,指定了 datadir 。一旦我更新了这个,服务器就正确启动了。
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.
我在overlayfs (overlay2) 上遇到了类似的错误,这是Mac 版Docker 上的默认设置。
使用 mysql 创建映像后,在映像上启动 mysql 时会发生该错误。
切换到“aufs”解决了这个问题。
(在 Docker for Mac 上,可以通过选择“首选项...”菜单,选择“守护进程”选项卡,然后选择“高级”选项卡来编辑“daemon.json”。)
/etc/docker/daemon.json :
参考:
https://github.com/moby/moby/issues/35503
https://qiita.com/Hige-Moja/items/7b1208f16997e2aa9028
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.
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 :
Ref:
https://github.com/moby/moby/issues/35503
https://qiita.com/Hige-Moja/items/7b1208f16997e2aa9028
如果您的服务器曾经运行MySQL,但现在出现此错误,那么卸载并重新安装MySQL就太过分了。
就我而言,服务器死机并带走了一些磁盘块。这影响了一些文件,包括 /var/lib/mysql/mysql/host.frm 和 /var/lib/mysql/mysql/proc.frm
幸运的是,我可以从另一台服务器复制这些,这让我克服了该表错误。
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.
如果您在 Windows 下使用 xampp,请执行以下操作:
转到 xampp 根目录,例如 c:\xampp
重命名文件夹“c:\xampp\mysql\data”
现在识别 mysqld.exe,在我的情况下这个 exe 是: C: \xampp\mysql\bin
当您位于该目录时,转到地址栏并键入 cmd,现在 cmd 位于同一目录中。
现在在cmd上输入: mysqld --initialize
now 正常启动mysql
If you are under windows with xampp, do this:
Go to xampp root directory, example c:\xampp
rename the folder "c:\xampp\mysql\data"
now identify mysqld.exe, this exe on my case are : C:\xampp\mysql\bin
when you are on that directory go to adress bar and type cmd, now the cmd are in the same directory.
now on cmd type : mysqld --initialize
now start mysql normally
我在 Ubuntu 14.04.2 LTS 上的情况与其他 my.cnf 的情况类似,但对我来说,原因是 ~/.my.cnf 是之前安装留下的。删除该文件并清除/重新安装 mysql-server 后,它工作正常。
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.
在
chown
和chgrp
'ing/var/lib/mysql
之后,根据 @Bad Programmer,您可能还需要执行以下命令:然后重新启动您的
mysqld
。After
chown
andchgrp
'ing/var/lib/mysql
per the answer by @Bad Programmer, you may also have to execute the following command:Then restart your
mysqld
.使用
yum remove mysql*
卸载mysql递归删除
/usr/bin/mysql< /code> 和
/var/lib/mysql
删除文件
/etc/my.cnf.rmp
使用
ps -e
检查进程以确保 mysql 未仍在运行。使用
reboot
重新启动服务器运行
yum install mysql-server
。这似乎也安装了 mysql 客户端作为依赖项。授予 mysql 所有权和组权限:
chown -R mysql /var/lib/mysql
chgrp -R mysql /var/lib/mysql
使用
service mysqld start
启动MySQL Daemon。Uninstall mysql using
yum remove mysql*
Recursively delete
/usr/bin/mysql
and/var/lib/mysql
Delete the file
/etc/my.cnf.rmp
Use
ps -e
to check the processes to make sure mysql isn't still running.Reboot server with
reboot
Run
yum install mysql-server
. This also seems to install the mysql client as a dependency.Give mysql ownership and group priveleges with:
chown -R mysql /var/lib/mysql
chgrp -R mysql /var/lib/mysql
Use
service mysqld start
to start MySQL Daemon.我在 arch linux 上也遇到了这个问题。问题是 pacman 将软件包安装在与 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:
Hope this helps someone!
我的问题的根源似乎是selinux,它被打开(强制)
在操作系统安装时自动。
我希望我的 mysql 位于 /data 中。
验证 my.cnf 具有:(
并将套接字保留在 /var/lib/mysql )
我执行了关闭mysqld的selinux的命令
(替代方法是完全关闭它):
我运行了以下命令:
我启动了 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:
(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):
I ran the following commands:
I started the mysql daemon and everything worked fine after that.
在 Centos 7 中为我工作
Worked for me in Centos 7
在 Windows 上启动之前初始化 mysql。
initialize mysql before start on windows.
当下载MySql zip版本时,如果直接运行
mysqld
,你会得到这个错误:You have to run below commandfirst:
Make sure your data folder is empty before this command 。
When download MySql zip version, if run
mysqld
directly, you'll get this error:You have to run below command first:
Make sure your data folder is empty before this command.
我刚刚在 OSX 上使用 mysql 5.7 时遇到了同样的问题:
I just met the same problem with mysql 5.7 on OSX:
只需这个命令就足以在 Centos 6.6 上发挥作用
Just this command is enough to do the magic on centos 6.6
如果移动 datadir,您不仅需要授予新的 datadir 权限,而且需要确保所有父目录都有权限。
我将数据目录移至硬盘,在 Ubuntu 中安装为:
我的数据目录是数据库。
我必须将每个媒体、用户和数据目录的权限设置为 771:
如果这不起作用,让 mysql 工作的另一种方法是更改 /etc/mysql/my 中的用户.cnf 到 root;尽管从安全角度来看这样做无疑存在一些问题。
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:
and my datadir was Databases.
I had to set permissions to 771 to each of the media, user and Data directories:
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.