1. 程式人生 > >Ubuntu server 安裝的mysql數據庫忘記密碼的解決方法

Ubuntu server 安裝的mysql數據庫忘記密碼的解決方法

network weight 數據 and ubunt statistic warning light div

客戶端連接時報錯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

2003 - Can‘t connect to MySQL server on ‘x.x.x.x‘ (10038)

mysql服務沒問題:

  1. sean@sean:~$ ps -ef|grep mysqld
  2. mysql 1219 1 0 21:09 ? 00:00:01 /usr/sbin/mysqld
  3. sean 10373 9602 0 21:38 pts/7 00:00:00 grep --color=auto mysqld

並且本地的登錄也能成功:

  1. sean@sean:~$ mysql -u root -h 127.0.0.1
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 40
  4. Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)
  5. Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  10. mysql>

但是使用外網地址卻無法登錄:

  1. sean@sean:~$ mysql -u root -h 192.168.137.128
  2. ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘192.168.137.128‘ (111)

於是修改了一下MySQL的配置文件:

  1. sean@sean:~$ sudo vi /etc/mysql/my.cnf

在bind-address= 127.0.0.1這一行前加#(註釋掉這行)

  1. # Instead of skip-networking the default is now to listen only on
  2. # localhost which is more compatible and is not less secure.
  3. #bind-address = 127.0.0.1

然後重啟mysql服務:

  1. sean@sean:~$ sudo service mysql restart
  2. mysql stop/waiting
  3. mysql start/running, process 11622

ERROR 1130: mysql 1130連接錯誤的有效解決方法

    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數據庫忘記密碼的解決方法