gpt4 book ai didi

mysql - 用户 '' @'localhost' 访问数据库 'emp' 被拒绝

转载 作者:行者123 更新时间:2023-11-30 00:57:13 25 4
gpt4 key购买 nike

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

被拒绝

当我查询显示补助金时

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

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

最佳答案

奇怪的是没有人回答。

这里有两个链接: 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

最后以正常方式重新启动mysql,无需使用--skip-grant-tables选项。要授予普通用户对某些数据库的权限,请参阅此答案:https://stackoverflow.com/a/15707789/520567

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

关于mysql - 用户 '' @'localhost' 访问数据库 'emp' 被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20450773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com