我在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;
我收到错误:
拒绝访问用户'root'@'localhost'(使用密码:YES)
答案 0 :(得分:2)
你所做的绝对正确,但我想这不是一个小原因。
当你要授予这样的特权时,你应该使用identified by password
:
mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
'*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;
答案 1 :(得分:0)
如果收到如下错误消息:
Warning: mysql_connect(): Access denied for user: ....
那么问题是您的应用程序无法access the database
。这可能有几个原因:
首先,确保db-config.php
(应用程序的连接文件)中的数据库设置正确,特别是MySQL用户的name
和password
,你的database
,以及MySQL服务器的名称。
如果您正在运行自己的服务器,则可能需要为MySQL用户提供适当的权限。以MySQL root用户身份登录MySQL并发出以下命令:
GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
答案 2 :(得分:0)