I did the following steps to use MySQL in Ubuntu:
我在Ubuntu中使用MySQL执行以下步骤:
sudo aptitude install php5-mysql mysql-server
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql -u root mysql
Change root password:
更改root密码:
mysql> UPDATE mysql.user SET Password=PASSWORD('SecurePassword') WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT
Modify /etc/mysql/my.cnf:
修改/etc/mysql/my.cnf:
[client]
user=root
password=SecurePassword
[mysqld]
...
default-time-zone = '+0:00'
Then:
然后:
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;
and I receive an error:
我收到一个错误:
Access denied for user 'root'@'localhost' (using password: YES)
用户'root'@'localhost'拒绝访问(使用密码:YES)
2 个解决方案
#1
2
It was absolutely correct what you did, but I guess it's not working for one small reason.
你做了什么绝对正确,但我想这不是一个小原因。
You should use identified by password
when you are going to grant privileges like this:
当您要授予如下权限时,您应该使用密码标识:
mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
'*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;
#2
0
If you get an error message like this:
如果您收到如下错误消息:
Warning: mysql_connect(): Access denied for user: ....
then the problem is that your application can not access the database
. This can have several causes:
那么问题是你的应用程序无法访问数据库。这可能有几个原因:
First of all, make sure the database settings in your db-config.php
(connection file for your application) are correct, specifically the name
and password
of your MySQL user, the name of your database
, and the name of your MySQL server.
首先,确保db-config.php(应用程序的连接文件)中的数据库设置正确,特别是MySQL用户的名称和密码,数据库名称以及MySQL服务器的名称。
If you're running your own server, you may need to give your MySQL user proper permissions. Log in to MySQL as the MySQL root user and issue these commands:
如果您正在运行自己的服务器,则可能需要为MySQL用户授予适当的权限。以MySQL root用户身份登录MySQL并发出以下命令:
GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
#1
2
It was absolutely correct what you did, but I guess it's not working for one small reason.
你做了什么绝对正确,但我想这不是一个小原因。
You should use identified by password
when you are going to grant privileges like this:
当您要授予如下权限时,您应该使用密码标识:
mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
'*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;
#2
0
If you get an error message like this:
如果您收到如下错误消息:
Warning: mysql_connect(): Access denied for user: ....
then the problem is that your application can not access the database
. This can have several causes:
那么问题是你的应用程序无法访问数据库。这可能有几个原因:
First of all, make sure the database settings in your db-config.php
(connection file for your application) are correct, specifically the name
and password
of your MySQL user, the name of your database
, and the name of your MySQL server.
首先,确保db-config.php(应用程序的连接文件)中的数据库设置正确,特别是MySQL用户的名称和密码,数据库名称以及MySQL服务器的名称。
If you're running your own server, you may need to give your MySQL user proper permissions. Log in to MySQL as the MySQL root user and issue these commands:
如果您正在运行自己的服务器,则可能需要为MySQL用户授予适当的权限。以MySQL root用户身份登录MySQL并发出以下命令:
GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;