php无法连接mysql数据库的解决方法

前两天,试着在本地虚拟机上布置网站程序来测试,发现给数据库root设置密码后,无法使用root+密码访问数据库。

 开始我是使用mysqladmin 来创建密码:

mysqladmin -uroot password “123456”

但发现无法用这个密码来连接数据库;

后来发现使用下面的方法来设定密码可以解决问题:


mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

mysql>  UPDATE user SET Password=password('123456') WHERE User = 'root' ; 

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> 


OK,问题解决。

评论
热度(1)