错误1044(42000):用户拒绝访问数据库'db'

时间:2022-02-02 19:19:30

I want to begin writing queries in MySQL.

我想开始在MySQL中编写查询。

show grants shows:

显示赠款节目:

+--------------------------------------+
| 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,但是当我想要创建一个用户时,我没有privil,而且我也不知道如何在我没有一个用户的情况下使用特权!

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

10 个解决方案

#1


181  

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.

不,您应该在bash中运行mysql -u root -p,而不是在mysql命令行中。如果你在mysql,你可以通过输入退出来退出。

#2


42  

You may need to set up a root account for your MySQL database:

您可能需要为MySQL数据库设置一个根帐户:

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

#3


24  

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

#4


8  

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允许我做大量的数据库搜索,但是由于路径设置,拒绝任何数据库创建。

#5


5  

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.

首先,如果您不熟悉命令行,请尝试从您的web浏览器中使用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

#6


4  

If you are in mysql shell, exit it by typing exit. It will return you to the command prompt. Now start mysql by using exactly the following command:

如果您在mysql shell中,则通过键入exit来退出。它会将您返回到命令提示符。现在使用以下命令启动mysql:

sudo mysql -u root -p

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

sudo mysql -你的用户名-p。

It will then ask you the mysql-account-password, and your mysql won't show any access privilege issue from now.

然后它会问你mysql-account-password,你的mysql现在不会显示任何访问权限问题。

#7


1  

@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: 错误1044(42000):用户拒绝访问数据库'db'

在bash命令行中键入正确的语法。如果您设置了密码,请输入密码;否则就按回车键。你应该得到一个类似的回应:

Hope this helps!

希望这可以帮助!

#8


1  

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提示。

错误1044(42000):用户拒绝访问数据库'db'

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 databases
  • 在database_name/table_name中,*表示所有数据库。
  • In hostname, to specify all hosts use '%'
  • 在主机名中,指定所有主机使用'%'

Step [3]: Get out of current mysql prompt by either entering quit / exit command or press Ctrl+D.

步骤[3]:通过输入quit / exit命令或按Ctrl+D退出当前的mysql提示。

Step [4]: Login to your new user

步骤[4]:登录到新用户。

$ mysql -uparsa -pyour_password

Step [5]: Create the database

步骤[5]:创建数据库。

mysql> create database `database_name`;

#9


0  

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>提示符,然后使用下面的命令(这是无效的)。

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

我也遇到过类似的僵局,所以分享了经验。

#10


0  

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!

我有一个正确的命令,上面的答案,我错过的是在工作台,我们提到“限制连接从主机”给用户,它默认为“%”-把这个改成“本地主机”,然后它连接好以后!

#1


181  

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.

不,您应该在bash中运行mysql -u root -p,而不是在mysql命令行中。如果你在mysql,你可以通过输入退出来退出。

#2


42  

You may need to set up a root account for your MySQL database:

您可能需要为MySQL数据库设置一个根帐户:

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

#3


24  

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

#4


8  

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允许我做大量的数据库搜索,但是由于路径设置,拒绝任何数据库创建。

#5


5  

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.

首先,如果您不熟悉命令行,请尝试从您的web浏览器中使用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

#6


4  

If you are in mysql shell, exit it by typing exit. It will return you to the command prompt. Now start mysql by using exactly the following command:

如果您在mysql shell中,则通过键入exit来退出。它会将您返回到命令提示符。现在使用以下命令启动mysql:

sudo mysql -u root -p

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

sudo mysql -你的用户名-p。

It will then ask you the mysql-account-password, and your mysql won't show any access privilege issue from now.

然后它会问你mysql-account-password,你的mysql现在不会显示任何访问权限问题。

#7


1  

@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: 错误1044(42000):用户拒绝访问数据库'db'

在bash命令行中键入正确的语法。如果您设置了密码,请输入密码;否则就按回车键。你应该得到一个类似的回应:

Hope this helps!

希望这可以帮助!

#8


1  

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提示。

错误1044(42000):用户拒绝访问数据库'db'

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 databases
  • 在database_name/table_name中,*表示所有数据库。
  • In hostname, to specify all hosts use '%'
  • 在主机名中,指定所有主机使用'%'

Step [3]: Get out of current mysql prompt by either entering quit / exit command or press Ctrl+D.

步骤[3]:通过输入quit / exit命令或按Ctrl+D退出当前的mysql提示。

Step [4]: Login to your new user

步骤[4]:登录到新用户。

$ mysql -uparsa -pyour_password

Step [5]: Create the database

步骤[5]:创建数据库。

mysql> create database `database_name`;

#9


0  

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>提示符,然后使用下面的命令(这是无效的)。

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

我也遇到过类似的僵局,所以分享了经验。

#10


0  

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!

我有一个正确的命令,上面的答案,我错过的是在工作台,我们提到“限制连接从主机”给用户,它默认为“%”-把这个改成“本地主机”,然后它连接好以后!