简体   繁体   English

错误 1044 (42000):用户 ''@'localhost' 对数据库 'db' 的访问被拒绝

[英]ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db'

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

No, you should run mysql -u root -p in bash, not at the MySQL command-line.不,您应该在 bash 中运行mysql -u root -p ,而不是在 MySQL 命令行中运行。 If you are in mysql, you can exit by typing exit .如果您在 mysql 中,则可以通过键入exit 退出

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

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';

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主机名可以是 IP 地址、localhost、127.0.0.1
  • In database_name / table_name , * means all databasesdatabase_name / table_name , * 表示所有数据库
  • In hostname , to specify all hosts use '%'hostname ,指定所有主机使用 '%'

Step [3]: Get out of current mysql prompt by either entering quit / exit command or press Ctrl+D .步骤 [3]:通过输入quit / exit命令或按Ctrl+D quit当前的 mysql 提示。

Step [4]: Login to your new user步骤 [4]:登录到您的新用户

$ mysql -uparsa -pyour_password

Step [5]: Create the database步骤[5]:创建数据库

mysql> create database `database_name`;

You might want to try the full login command:您可能想尝试完整的登录命令:

mysql -h host -u root -p 

where host would be 127.0.0.1 .其中 host 是127.0.0.1

Do this just to make sure cooperation exists.这样做只是为了确保存在合作。

Using mysql -u root -p allows me to do aa lot of database searching, but refuses any database creation due to a path setting.使用mysql -u root -p允许我进行大量数据库搜索,但由于路径设置而拒绝任何数据库创建。

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将不会显示任何访问权限问题。

First, if you are unfamiliar with the command line, try using phpmyadmin from your webbrowser.首先,如果您不熟悉命令行,请尝试从您的网络浏览器使用 phpmyadmin。 This will make sure you actually have a mysql database created and a username.这将确保您确实创建了一个 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

@Nickparsa … you have 2 issues: @Nickparsa ......你有两个问题:

1). 1)。 mysql -uroot -p should be typed in bash (also known as your terminal) not in MySQL command-line. mysql -uroot -p应该在 bash(也称为终端)中输入,而不是在 MySQL 命令行中输入。 You fix this error by typing您可以通过键入来修复此错误

exit

in your MySQL command-line.在您的 MySQL 命令行中。 Now you are back in your bash/terminal command-line.现在您又回到了 bash/终端命令行。

2). 2)。 You have a syntax error:你有一个语法错误:

mysql -uroot -p; 

the semicolon in front of -p needs to go. -p 前面的分号需要去掉。 The correct syntax is:正确的语法是:

mysql -uroot -p

type the correct syntax in your bash commandline.在 bash 命令行中输入正确的语法。 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:您应该得到与此类似的响应:在此处输入图片说明

Hope this helps!希望这可以帮助!

connect mysql with sudo & gives permission for the necessary user using,将 mysql 与 sudo 连接并授予必要的用户使用权限,

sudo mysql -u user;
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost';

Most Developers log-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我遇到了类似的僵局,所以分享经验

根据上述答案,我的命令是正确的,我错过的是在工作台上,我们在那里为用户提到了“限制来自主机的连接”,它默认为“%” - 将其更改为“localhost”,此后连接正常!

I'm using roles to confer least privilege on my database application users.我使用角色为我的数据库应用程序用户授予最小权限。 I kept getting 'ERROR 1044 (42000): Access denied for user...' until I RTFM and discovered I had to give each user a default role(s) in order their account could be authenticated when they logged in.我一直收到“错误 1044 (42000):用户访问被拒绝...”,直到我 RTFM 发现我必须给每个用户一个默认角色,以便他们的帐户在登录时可以通过身份验证。

#create a role
CREATE ROLE 'rolename';

#give necessary privileges to role
GRANT INSERT, UPDATE, DELETE, SELECT ON database.table TO 'rolename';

#create user
CREATE USER 'username'@'host' IDENTIFIED BY 'password';

#give the user a role(s)
GRANT 'rolename' TO 'username'@'host';

#set the user's default otherwise it's ERROR 1044
SET DEFAULT ROLE 'rolename' FOR 'username'@'host';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误1044(42000):用户&#39;@&#39;localhost&#39;对数据库&#39;mysql&#39;的访问被拒绝 - ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 错误1044(42000):用户&#39;&#39;@localhost对数据库的访问被拒绝 - ERROR 1044 (42000) : Access denied for user ' '@localhost to database 错误 1044 (42000):用户 &#39;root&#39;@&#39;localhost&#39; 对数据库 &#39;newdb&#39; 的访问被拒绝 - ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'newdb' ERROR 1044(42000):用户&#39;&#39;@ localhost&#39;拒绝访问 - ERROR 1044 (42000): Access denied for user ''@'localhost' MySQL 1044(42000):使用Mac对用户&#39;@&#39;localhost&#39;到数据库&#39;mysql&#39;的访问被拒绝 - MySQL 1044 (42000): Access denied for user ' '@'localhost' to database 'mysql' with Mac 错误 1044 拒绝用户 ''@'localhost' 访问数据库 - Error 1044 access denied for user ''@'localhost' to database 错误 1044 (42000):拒绝用户 'root'@'localhost' 访问数据库 (MySQL - MariaDB) - ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database (MySQL - MariaDB) sakila错误1044(42000),位于第46412行:用户&#39;ted&#39;@&#39;localhost&#39;对数据库&#39;sakila&#39;的访问被拒绝 - sakila ERROR 1044 (42000) at line 46412: Access denied for user 'ted'@'localhost' to database 'sakila' mysql&gt; 使用 mysql; 但是......错误1044(42000):用户&#39;&#39;@&#39;localhost&#39;对数据库&#39;mysql&#39;的访问被拒绝 - mysql> use mysql; but … ERROR 1044 (42000): Access denied for user '' @ 'localhost' to database 'mysql' 错误 1044 (42000):拒绝用户访问 - ERROR 1044 (42000): Access denied for user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM