MySQL 错误 1044 (42000):用户 ''@'localhost' 对数据库 'db' 的访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8838777/
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
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db'
提问by Nickool
I want to begin writing queries in MySQL.
我想开始在 MySQL 中编写查询。
show grants
shows:
show grants
显示:
+--------------------------------------+
| Grants for @localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
I do not have any user-id but when I want to make a user I don't have privilleges, also I don't know how to make privileges when even I don't have one user!
我没有任何用户 ID,但是当我想创建一个用户时,我没有特权,即使我没有一个用户,我也不知道如何获得特权!
mysql> CREATE USER 'parsa'@'localhost' IDENTIFIED BY 'parsa';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER pr
ivilege(s) for this operation
I tried to sign in as root:
我尝试以 root 身份登录:
mysql> mysql -u root -p;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-u root -p' at line 1
mysql> mysql -u root -p root;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-u root -p root' at line 1
回答by Nowhy
No, you should run mysql -u root -p
in bash, not at the MySQL command-line.
If you are in mysql, you can exit by typing exit.
不,您应该mysql -u root -p
在 bash 中运行,而不是在 MySQL 命令行中运行。如果您在 mysql 中,则可以通过键入exit 退出。
回答by soleshoe
You may need to set up a root account for your MySQL database:
您可能需要为 MySQL 数据库设置一个 root 帐户:
In the terminal type:
在终端类型中:
mysqladmin -u root password 'root password goes here'
And then to invoke the MySQL client:
然后调用 MySQL 客户端:
mysql -h localhost -u root -p
回答by Lefteris E
I was brought here by a different problem. Whenever I tried to login, i got that message because instead of authenticating correctly I logged in as anonymous user. The solution to my problem was:
我被一个不同的问题带到这里。每当我尝试登录时,我都会收到该消息,因为我没有正确进行身份验证,而是以匿名用户身份登录。我的问题的解决方案是:
To see which user you are, and whose permissions you have:
要查看您是哪个用户以及您拥有谁的权限:
select user(), current_user();
To delete the pesky anonymous user:
删除讨厌的匿名用户:
drop user ''@'localhost';
回答by theBuzzyCoder
This is something to do with user permissions. Giving proper grants will solve this issue.
这与用户权限有关。给予适当的赠款将解决这个问题。
Step [1]: Open terminal and run this command
步骤[1]:打开终端并运行此命令
$ mysql -uroot -p
Output [1]: This should give you mysql prompt shown below
输出 [1]:这应该给你如下所示的 mysql 提示
Step [2]:
第2步]:
mysql> CREATE USER 'parsa'@'localhost' IDENTIFIED BY 'your_password';
mysql> grant all privileges on *.* to 'parsa'@'localhost';
Syntax:
句法:
mysql> grant all privileges on `database_name`.`table_name` to 'user_name'@'hostname';
Note:
- hostname can be IP address, localhost, 127.0.0.1
- In
database_name
/table_name
, * means all databases- In
hostname
, to specify all hosts use '%'
笔记:
- 主机名可以是 IP 地址、localhost、127.0.0.1
- 在
database_name
/table_name
, * 表示所有数据库- 在
hostname
, 指定所有主机使用 '%'
Step [3]: Get out of current mysql prompt by either entering quit
/ exit
command or press Ctrl+D
.
步骤 [3]:通过输入quit
/exit
命令或按退出当前的 mysql 提示Ctrl+D
。
Step [4]: Login to your new user
步骤 [4]:登录到您的新用户
$ mysql -uparsa -pyour_password
Step [5]: Create the database
步骤[5]:创建数据库
mysql> create database `database_name`;
回答by Ray
You might want to try the full login command:
您可能想尝试完整的登录命令:
mysql -h host -u root -p
where host would be 127.0.0.1
.
主人会在哪里127.0.0.1
。
Do this just to make sure cooperation exists.
这样做只是为了确保存在合作。
Using mysql -u root -p
allows me to do a a lot of database searching, but refuses any database creation due to a path setting.
使用mysql -u root -p
允许我进行大量的数据库搜索,但由于路径设置而拒绝任何数据库创建。
回答by fabiog
First, if you are unfamiliar with the command line, try using phpmyadmin from your webbrowser. This will make sure you actually have a mysql database created and a username.
首先,如果您不熟悉命令行,请尝试从您的网络浏览器使用 phpmyadmin。这将确保您确实创建了一个 mysql 数据库和一个用户名。
This is how you connect from the command line (bash):
这是从命令行 (bash) 连接的方式:
mysql -h hostname -u username -p database_name
For example:
例如:
fabio@crunchbang ~ $ mysql -h 127.0.0.1 -u fabio -p fabiodb
回答by Kshitij Mittal
If you are in a MySQL
shell, exit it by typing exit, which will return you to the command prompt.
如果您在MySQL
shell 中,请通过键入exit退出它,这将使您返回到命令提示符。
Now start MySQL
by using exactly the following command:
现在开始MySQL
使用以下命令:
sudo mysql -u root -p
If your username is something other than root, replace 'root' in the above command with your username:
如果您的用户名不是 root,请将上述命令中的“root”替换为您的用户名:
sudo mysql -u <your-user-name> -p
It will then ask you the MySQL
account/password, and your MySQL
won't show any access privilege issue then on.
然后它会询问您的MySQL
帐户/密码,然后您MySQL
将不会显示任何访问权限问题。
回答by Uzzar
@Nickparsa … you have 2 issues:
@Nickparsa ......你有两个问题:
1). mysql -uroot -p
should be typed in bash (also known as your terminal) not in MySQL command-line. You fix this error by typing
1)。mysql -uroot -p
应该在 bash(也称为终端)中输入,而不是在 MySQL 命令行中输入。您可以通过键入来修复此错误
exit
in your MySQL command-line. Now you are back in your bash/terminal command-line.
在您的 MySQL 命令行中。现在您又回到了 bash/终端命令行。
2). You have a syntax error:
2)。你有一个语法错误:
mysql -uroot -p;
the semicolon in front of -p needs to go. The correct syntax is:
-p 前面的分号需要去掉。正确的语法是:
mysql -uroot -p
type the correct syntax in your bash commandline. Enter a password if you have one set up; else just hit the enter button. You should get a response that is similar to this:
在 bash 命令行中输入正确的语法。如果您设置了密码,请输入密码;否则只需按回车键。您应该得到与此类似的响应:
Hope this helps!
希望这可以帮助!
回答by Devrath
Most Developerslog-in to server(I assume you r having user-name and password for mysql database) then from Bash they switch to mysql> prompt
then use the command below(which doesn't work
大多数开发人员登录到服务器(我假设你有 mysql 数据库的用户名和密码)然后从 Bash 切换到mysql> prompt
然后使用下面的命令(这不起作用
mysql -h localhost -u root -p
What needs to be done is use the above command in the bash prompt--> on doing so it will ask for password if given it will take directly to mysql prompt and
需要做的是在 bash 提示符下使用上面的命令-->这样做它会要求输入密码,如果给出它会直接进入 mysql 提示符和
then database, table can be created one by one
然后数据库,表可以一一创建
I faced similar deadlock so sharing the experience
我遇到了类似的僵局,所以分享经验
回答by killjoy
I had the command correct per above answers, what I missed on was on the Workbench, where we mention 'Limit Connectivity from Host' for the user, it defaults to "%" - change this to "localhost" and it connects fine thereafter!
根据上述答案,我的命令是正确的,我错过的是在工作台上,我们在那里为用户提到了“限制来自主机的连接”,它默认为“%” - 将其更改为“localhost”,此后连接正常!