Linux 致命错误:无法打开和锁定权限表:表 'mysql.host' 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9083408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
提问by Bad Programmer
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:
我在一台在 RHEL 5 上重新安装的服务器上。我能够很好地安装 Apache 和 PHP。但是我的 MySQL 安装遇到了严重的问题。我尝试了以下方法:
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。
采纳答案by Bad Programmer
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.
卸载 mysql 使用
yum remove mysql*
递归删除
/usr/bin/mysql
和/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守护进程。
回答by Ilane
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 守护进程,之后一切正常。
回答by Felipe Loredo
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.
我已经删除了所有特殊字符,一切正常。
回答by FilBot3
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.
然后我能够回到我的数据库并在我第一次使用它们之后再次配置它们。
回答by Chris Labonne
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. For example I used kickstart to install the following:
以最小安装方式安装 CentOS EL6。例如,我使用 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
. I found that my system has a default my.cnf
in /etc
and this contains:
您会发现上述列表的依赖项之一是mysql-libs
. 我发现我的系统有一个默认值my.cnf
,/etc
其中包含:
[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
.
当您从Generic Linux (Architecture Independent), Compressed TAR Archive
默认数据目录构建时,/usr/local/mysql/data
它与/etc/my.cnf
已经存在的定义datadir=/var/lib/mysql
. 此外,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 的体验是不同的。
回答by bk0
After chown
and chgrp
'ing /var/lib/mysql
per the answer by @Bad Programmer, you may also have to execute the following command:
经过chown
与chgrp
“荷兰国际集团/var/lib/mysql
每通过回答@Bad程序员,你可能还需要执行以下命令:
sudo mysql_install_db --user=mysql --ldata=/var/lib/mysql
Then restart your mysqld
.
然后重新启动您的mysqld
.
回答by zagatztu
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.
我在尝试启动服务器并遵循“已检查”解决方案时遇到了同样的问题。但是还是有问题。问题是我的 /etc/my.cnf 文件没有指向我在定义 --datadir 的情况下执行 mysql_install_db 时定义的指定数据目录。一旦我更新了这个,服务器就正确启动了。
回答by Kohjah Breese
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, userand 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; though there are no doubt some issues with doing that from a security perspective.
如果这不起作用,另一种让 mysql 工作的方法是将 /etc/mysql/my.cnf 中的用户更改为 root;尽管从安全角度来看,这样做无疑存在一些问题。
回答by JVJ
mysql_install_db –-user=mysql --ldata=/var/lib/mysql
Worked for me in Centos 7
在 Centos 7 为我工作
回答by eja
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.
我在 Ubuntu 14.04.2 LTS 上的情况与 my.cnf 的情况类似,但对我来说,原因是 ~/.my.cnf 是以前安装时遗留下来的。删除该文件并清除/重新安装 mysql-server 后,它运行良好。