gpt4 book ai didi

MYSQL 访问被拒绝用户 'root' @'localhost'

转载 作者:IT王子 更新时间:2023-10-29 00:28:39 24 4
gpt4 key购买 nike

我做了以下步骤在 Ubuntu 中使用 MySQL:

sudo aptitude install php5-mysql mysql-server
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql -u root mysql

修改root密码:

mysql> UPDATE mysql.user SET Password=PASSWORD('SecurePassword') WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

修改/etc/mysql/my.cnf:

[client]
user=root
password=SecurePassword
[mysqld]
...
default-time-zone = '+0:00'

然后:

sudo service mysql start
mysql -u root
mysql> SHOW GRANTS FOR root@localhost
+--------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+--------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '[here is the Securepassword]' |
+-------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;

我收到一个错误:

Access denied for user 'root'@'localhost' (using password: YES)

最佳答案

你所做的绝对正确,但我想它不起作用是因为一个小原因。

当你要授予这样的权限时,你应该使用 identified by password:

mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
'*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;

关于MYSQL 访问被拒绝用户 'root' @'localhost',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18328153/

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