无法打开和锁定权限表:表 'mysql.user' 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34516664/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:30:48  来源:igfitidea点击:

Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

mysqlmysql-5.7

提问by BValluri

I installed MySQL community server 5.7.10 using binary zip. I extracted the zip in c:\mysqland created the data folder in c:\mysql\data. I created the config file as my.iniand placed it in c:\mysql(root folder of extracted zip). Below is the content of the my.inifile

我使用二进制 zip 安装了 MySQL 社区服务器 5.7.10。我解压缩了 zipc:\mysql文件并在c:\mysql\data. 我创建了配置文件my.ini并将其放置在c:\mysql(解压缩的 zip 的根文件夹)中。下面是my.ini文件内容

# set basedir to your installation path
basedir=C:\mysql
# set datadir to the location of your data directory
datadir=C:\mysql\data

I'm trying to start MySQL using mysqld --console, but the process is aborted with the below error.

我正在尝试使用 启动 MySQL mysqld --console,但该过程因以下错误而中止。

2015-12-29T18:04:01.141930Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2015-12-29T18:04:01.141930Z 0 [ERROR] Aborting 

Any help on this will be appreciated.

对此的任何帮助将不胜感激。

回答by anonymous

You have to initialize the data directory by running the following command

您必须通过运行以下命令来初始化数据目录

mysqld --initialize[with random root password]

mysqld --initialize[使用随机root密码]

mysqld --initialize-insecure[with blank root password]

mysqld --initialize-insecure[root 密码为空]

回答by Charlie

On Maria DB you use mysql_install_db. In my case I use an environment variable for the data path. Not only does mysqldneed to know where the data is (specified via commandline), but so does the install script.

在 Maria DB 上,您使用mysql_install_db. 在我的情况下,我使用环境变量作为数据路径。不仅mysqld需要知道数据在哪里(通过命令行指定),而且安装脚本也需要知道。

Here's how you can call the install script specifying the datapath:

以下是调用指定数据路径的安装脚本的方法:

mysql_install_db --user=root --datadir=$db_datapath

回答by Kenovo

mysqld --initialize to initialize the data directory then mysqld &

mysqld --initialize 初始化数据目录然后mysqld &

If you had already launched mysqld& without mysqld --initialize you might have to delete all files in your data directory

如果您已经在没有 mysqld --initialize 的情况下启动了 mysqld&,您可能必须删除数据目录中的所有文件

You can also modify /etc/my.cnf to add a custom path to your data directory like this :

您还可以修改 /etc/my.cnf 以将自定义路径添加到您的数据目录,如下所示:

[mysqld]
...  
datadir=/path/to/directory

回答by Muthahir Nawaz

As suggested above, i had similar issue with mysql-5.7.18,
i did this in this way

1. Executed this command from "MYSQL_HOME\bin\mysqld.exe --initialize-insecure"
2. then started "MYSQL_HOME\bin\mysqld.exe"
3. Connect workbench to this localhost:3306 with username 'root'
4. then executed this query "SET PASSWORD FOR 'root'@'localhost' = 'root';"

如上所述,我在 mysql-5.7.18 上遇到了类似的问题,
我是这样做的

1. 从“MYSQL_HOME\bin\mysqld.exe --initialize-insecure”执行此命令
2.然后启动“MYSQL_HOME\bin\ mysqld.exe”
3. 使用用户名 'root' 将工作台连接到这个 localhost:3306
4. 然后执行这个查询“SET PASSWORD FOR 'root'@'localhost' = 'root';”

password was also updated successfully.

密码也更新成功。

回答by Gerfried

I had the same problem. For some reason --initializedid not work. After about 5 hours of trial and error with different parameters, configs and commands I found out that the problem was caused by the file system.

我有同样的问题。由于某种原因--initialize没有工作。在使用不同的参数、配置和命令进行了大约 5 个小时的反复试验后,我发现问题是由文件系统引起的。

I wanted to run a database on a large USB HDD drive. Drives larger than 2 TB are GPT partitioned! Here is a bug report with a solution:

我想在大型 USB 硬盘驱动器上运行数据库。大于 2 TB 的驱动器是 GPT 分区的!这是一个带有解决方案的错误报告:

https://bugs.mysql.com/bug.php?id=28913

https://bugs.mysql.com/bug.php?id=28913

In short words: Add the following line to your my.ini:

简而言之:将以下行添加到您的 my.ini 中:

innodb_flush_method=normal

I had this problem with mysql 5.7 on Windows.

我在 Windows 上使用 mysql 5.7 时遇到了这个问题。

回答by Dalthon

in laragon delete all internal data files from "C:\laragon\data\mysql" and restart it, that worked for me

在 laragon 中从“C:\laragon\data\mysql”中删除所有内部数据文件并重新启动它,这对我有用