用户''@ localhost'拒绝访问数据库'\ temp'

时间:2013-12-08 07:02:23

标签: mysql

当我尝试创建数据库时,出现错误  用户'@'localhost拒绝访问数据库emp

当我查询show grants

mysql> show grants;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)

我无法以root用户身份进行访问。

我找不到用户名。

此外,当我尝试创建新用户获取错误时

mysql> create user 'user1'@'localhost';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

如何创建新用户和数据库。

1 个答案:

答案 0 :(得分:0)

奇怪的是没有人回答。

以下是两个链接: http://mysqlpreacher.com/wordpress/2011/03/recovering-a-mysql-root-password-three-solutions/ http://iwtf.net/2010/01/05/recovering-a-lost-mysql-root-password/

基本上你需要--skip-grant-tables。从其中一个网站粘贴:

The solution
This was actually pretty simple. Its just a case of restarting mysql without the authentication tables loaded

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

This stops MySQL and reloads it without the authentication (aka grant) tables, meaning we can connect to MySQL without a password. Beware this locks out all of your customers and applications until the password reset process is completed. Now we need to go in an reset the password

sudo su - 
mysql -u root -p

It will prompt you for a password, just hit enter.

现在创建您想要的用户。有类似的东西:

grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option
grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option

最后在没有--skip-grant-tables选项的情况下以正常方式重启mysql。要授予某些数据库的普通用户权限,请参阅以下答案:https://stackoverflow.com/a/15707789/520567

使用上述命令创建普通用户是不安全的。只有root用户才能像那样创建它们。