标签:sudo nec where 修改 问题 mysql you 解决 other
客户端连接时报错MySQL数据库出现:Error 1045错误时,就表明输入的用户名或密码错误被拒绝访问了。
解决办法可以分为以下几步:
1.修改mysql配置文件,使得可以无密码登录mysql
sudo vim /etc/mysql/my.cnf
在[mysqld]项下添加
skip-grant-tables
2.重启mysql服务
sudo service mysql restart
3.无密码登录mysql
mysql -uroot -p
4.修改管理员密码
use mysql;
update user set password=password(‘123‘) where user=‘root‘;
flush privileges;
exit;
5.还原配置文件
6.可以使用下面的命令登录
mysql -uroot -p123
mysql服务没问题:
并且本地的登录也能成功:
但是使用外网地址却无法登录:
于是修改了一下MySQL的配置文件:
在bind-address= 127.0.0.1这一行前加#(注释掉这行)
然后重启mysql服务:
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> select host, user, password from user; +-----------+------------------+-------------------------------------------+ | host | user | password | +-----------+------------------+-------------------------------------------+ | localhost | root | | | sean | root | | | 127.0.0.1 | root | | | ::1 | root | | | localhost | debian-sys-maint | *0AA379AB8AFD785B32D661A07E9D5C7A24E3B186 | +-----------+------------------+-------------------------------------------+ 5 rows in set (0.00 sec) mysql> update user set host = "%" where host = "sean" and user = "root"; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select host, user, password from user; +-----------+------------------+-------------------------------------------+ | host | user | password | +-----------+------------------+-------------------------------------------+ | localhost | root | | | % | root | | | 127.0.0.1 | root | | | ::1 | root | | | localhost | debian-sys-maint | *0AA379AB8AFD785B32D661A07E9D5C7A24E3B186 | +-----------+------------------+-------------------------------------------+ 5 rows in set (0.00 sec)
使用Navicat就可以成功连接至数据库了.
Ubuntu server 安装的mysql数据库忘记密码的解决方法
标签:sudo nec where 修改 问题 mysql you 解决 other
原文地址:http://www.cnblogs.com/ranxf/p/7919836.html