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

发布于 2024-12-31 21:47:00 字数 525 浏览 1 评论 0原文

我所在的服务器在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

世俗缘 2025-01-07 21:47:01

对于我自己来说,我必须这样做:

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

然后我能够回到我的数据库并在我第一次攻击它们后再次配置它们。

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.

江湖彼岸 2025-01-07 21:47:01

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

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

悟红尘 2025-01-07 21:47:01

就我而言,MySQL 数据文件夹的路径有一个特殊字符“ç”,它让我得到......

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

我已经删除了所有特殊字符并且一切正常。

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.

半葬歌 2025-01-07 21:47:01

在 CentOS EL 6 甚至更早的版本上,有一种方法可以解决同样的问题。

使用最小安装安装 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

您会发现上面列表的依赖项之一是mysql-libs。我发现我的系统在 /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

当您从 Generic Linux(架构独立)构建时,压缩的 TAR 存档 你的默认数据目录是 /usr/local/mysql/data ,它与已经存在的定义 datadir= 的 /etc/my.cnf 冲突/var/lib/mysql。此外,同一文件中定义的 pid-file 没有 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:

%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.

放血 2025-01-07 21:47:01

我在尝试启动服务器时遇到了同样的问题,并遵循“已检查”的解决方案。
但仍然有问题。问题是我的 /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.

零度℉ 2025-01-07 21:47:01

我在overlayfs (overlay2) 上遇到了类似的错误,这是Mac 版Docker 上的默认设置。
使用 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

切换到“aufs”解决了这个问题。
(在 Docker for Mac 上,可以通过选择“首选项...”菜单,选择“守护进程”选项卡,然后选择“高级”选项卡来编辑“daemon.json”。)

/etc/docker/daemon.json :

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

参考:

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.

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

俏︾媚 2025-01-07 21:47:01

如果您的服务器曾经运行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.

窝囊感情。 2025-01-07 21:47:01

如果您在 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

没︽人懂的悲伤 2025-01-07 21:47:01

我在 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.

非要怀念 2025-01-07 21:47:00

chownchgrp'ing /var/lib/mysql 之后,根据 @Bad Programmer,您可能还需要执行以下命令:

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

然后重新启动您的 mysqld

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.

你的笑 2025-01-07 21:47:00
  1. 使用yum remove mysql*卸载mysql

  2. 递归删除/usr/bin/mysql< /code> 和 /var/lib/mysql

  3. 删除文件/etc/my.cnf.rmp

  4. 使用ps -e 检查进程以确保 mysql 未仍在运行。

  5. 使用reboot重新启动服务器

  6. 运行yum install mysql-server。这似乎也安装了 mysql 客户端作为依赖项。

  7. 授予 mysql 所有权和组权限:

    chown -R mysql /var/lib/mysql

    chgrp -R mysql /var/lib/mysql

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

  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.

迷爱 2025-01-07 21:47:00

我在 arch linux 上也遇到了这个问题。问题是 pacman 将软件包安装在与 MySQL 预期不同的位置。我能够解决这个问题:

sudo mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/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!

囚我心虐我身 2025-01-07 21:47:00

我的问题的根源似乎是selinux,它被打开(强制)
在操作系统安装时自动。

我希望我的 mysql 位于 /data 中。

验证 my.cnf 具有:(

datadir=/data/mysql

并将套接字保留在 /var/lib/mysql )
我执行了关闭mysqld的selinux的命令
(替代方法是完全关闭它):

setsebool -P mysqld_disable_trans=1

我运行了以下命令:

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

我启动了 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.

傲世九天 2025-01-07 21:47:00
mysql_install_db –-user=mysql --ldata=/var/lib/mysql

在 Centos 7 中为我工作

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

Worked for me in Centos 7

萌面超妹 2025-01-07 21:47:00

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

mysqld --initialize

initialize mysql before start on windows.

mysqld --initialize
瘫痪情歌 2025-01-07 21:47:00

当下载MySql zip版本时,如果直接运行mysqld,你会得到这个错误:

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 commandfirst:

mysqld --initialize

Make sure your data folder is empty before this command 。

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.

爱殇璃 2025-01-07 21:47:00

我刚刚在 OSX 上使用 mysql 5.7 时遇到了同样的问题:

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

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

rm -rf {datadir}
mysqld --initialize --datadir {datadir}
mysqld --datadir {datadir}
北笙凉宸 2025-01-07 21:47:00

只需这个命令就足以在 Centos 6.6 上发挥作用

mysql_install_db

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

mysql_install_db
完美的未来在梦里 2025-01-07 21:47:00

如果移动 datadir,您不仅需要授予新的 datadir 权限,而且需要确保所有父目录都有权限。

我将数据目录移至硬盘,在 Ubuntu 中安装为:

/media/*user*/Data/

我的数据目录是数据库

我必须将每个媒体、用户和数据目录的权限设置为 771:

sudo chmod 771 *DIR*

如果这不起作用,让 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:

/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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文