表 'mysql.user' 不存在:错误

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

Table 'mysql.user' doesn't exist:ERROR

mysql

提问by Abilash Ravichandran

I am creating a db in mysql for a java program.My program works well in my friends system.But I have some problem with my mysql.

我正在为 java 程序在 mysql 中创建一个数据库。我的程序在我朋友的系统中运行良好。但是我的 mysql 有一些问题。

The query is below:

查询如下:

mysql> create database sampledb;

Query OK, 1 row affected (0.00 sec)

mysql> use sampledb;

Database changed

mysql> create user zebronics identified by 'zebra123';

ERROR 1146 (42S02): Table 'mysql.user' doesn't exist

I cant create any user for my db.Please help??

我无法为我的数据库创建任何用户。请帮忙??

回答by Markus

My solution was to run

我的解决方案是运行

mysql_upgrade -u root

Scenario: I updated the MySQL version on my Mac with 'homebrew upgrade'. Afterwards, some stuff worked, but other commands raised the error described in the question.

场景:我使用“自制升级”更新了 Mac 上的 MySQL 版本。之后,一些东西起作用了,但其他命令引发了问题中描述的错误。

回答by jnrbsn

Looks like something is messed up with your MySQL installation. The mysql.usertable should definitely exist. Try running the command below on your server to create the tables in the database called mysql:

看起来您的 MySQL 安装出了点问题。该mysql.user表应该肯定存在。尝试在您的服务器上运行以下命令以在名为 的数据库中创建表mysql

mysql_install_db

If that doesn't work, maybe the permissions on your MySQL data directory are messed up. Look at a "known good" installation as a reference for what the permissions should be.

如果这不起作用,可能是您的 MySQL 数据目录的权限搞砸了。查看“已知良好”安装作为权限应该是什么的参考。

You could also try re-installing MySQL completely.

您也可以尝试完全重新安装 MySQL。

回答by Mark M

Your database may be corrupt. Try to check if mysql.user exists:

您的数据库可能已损坏。尝试检查 mysql.user 是否存在:

use mysql;
select * from user;

If these are missing you can try recreating the tables by using

如果缺少这些,您可以尝试使用重新创建表

mysql_install_db

mysql_install_db

or you may have to clean (completely remove it) and reinstall MySQL.

或者您可能必须清理(完全删除它)并重新安装 MySQL。

回答by Matthias Nott

Same issue here as lxxxvi describes. Running

此处与 lxxxvi 描述的问题相同。跑步

    mysql_upgrade -u root

allowed me to then successfully enter a password that

允许我然后成功输入密码

    mysql_secure_installation

was waiting for.

正在等待。

回答by Namphibian

You can run the following query to check for the existance of the user table.

您可以运行以下查询来检查用户表是否存在。

SELECT * FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '%user%'

See if you can find a row with the following values in

看看你能不能找到具有以下值的行

mysql   user    BASE TABLE  MyISAM  

If you cant find this table look at the following link to rebuild the database How to recover/recreate mysql's default 'mysql' database

如果找不到此表,请查看以下链接以重建数据库如何恢复/重新创建 mysql 的默认 'mysql' 数据库

回答by ManMohan Vyas

 show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| datapass_schema    |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.05 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables
    -> ;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.00 sec)

mysql> create user m identified by 'm';
Query OK, 0 rows affected (0.02 sec)

check for the database mysql and table user as shown above if that dosent work, your mysql installation is not proper.

检查数据库 mysql 和表用户,如上所示,如果没有工作,则您的 mysql 安装不正确。

use the below command as mention in other post to install tables again

使用其他帖子中提到的以下命令再次安装表

mysql_install_db

回答by ray6080

Try run mysqladmin reload, which is located in /usr/loca/mysql/bin/on mac.

尝试运行mysqladmin reload,它位于/usr/loca/mysql/bin/mac 中。

回答by kibika wanjala

'Error Code: 1046'. 

This error shows that the table does not exist may sometimes be caused by having selected a different database and running a query referring to another table. The results indicates 'No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar'. Will solve the issue and it worked for me very well.

此错误表明该表不存在有时可能是由于选择了不同的数据库并运行引用另一个表的查询造成的。结果显示“未选择数据库选择要使用的默认数据库,方法是在侧栏中的 SCHEMAS 列表中双击其名称”。将解决这个问题,它对我很有效。