Ubuntu server 安裝的mysql資料庫忘記密碼的解決方案

來源:互聯網
上載者:User

標籤: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

 

 

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

mysql服務沒問題:

  1. [email protected]:~$ 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. [email protected]:~$ 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.   
  6. Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.  
  7.   
  8. Oracle is a registered trademark of Oracle Corporation and/or its  
  9. affiliates. Other names may be trademarks of their respective  
  10. owners.  
  11.   
  12. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.  
  13.   
  14. mysql>   

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

  1. [email protected]:~$ 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. [email protected]:~$ 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. [email protected]:~$ 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資料庫忘記密碼的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.