Windows系統下,Navicat Premium連接MySQL數據庫bug

目錄

 1、ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

[1]、問題查找過程

[2]、解決方案步驟

2、1045-Access denied for user 'root'@'localhost'(using password:YES)

[2]、解決方案步驟


  

 1、ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

[1]、問題查找過程

(1)MyEclipse》HibernateTest1.java(測試Hibernate框架,使用main程序入口測試)右鍵》Run As》Java Application》控制檯顯示 

Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Caused by: java.net.ConnectException: Connection refused: connect

(2.1)打開Navicat Premium》雙擊連接的MySQL數據庫》彈窗提示

2003-Cant't connect to MySQL server on 'localhost'(10061 "Unknown error")

(2.2) 桌面》計算機 》D:\DevelopSoft\database\MySQL\MySQL5_5_x64\soft\bin 在此路徑框處輸入cmd》DOS彈窗》D:\DevelopSoft\database\MySQL\MySQL5_5_x64\soft\bin> mysql -u root

ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

(3)桌面》計算機》右鍵 管理》服務和應用程序》服務》選中名稱爲 MySQL》右鍵 啓動》彈窗提示 

Windows 無法啓動 MySQL服務(位於 本地計算機 上)。錯誤1067:進程意外終止。

(4.1)點擊“開始→運行”,輸入eventvwr,點擊“確定”,就可以打開事件查看器》Windows日誌》應用程序》在此處找到錯誤原因

Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

Server socket created on IP: '0.0.0.0'.

  - '0.0.0.0' resolves to '0.0.0.0';

Server hostname (bind-address): '0.0.0.0'; port: 3306

Plugin 'FEDERATED' is disabled.

For more information, see Help and Support Center at https://www.mysql.com/

(4.2) 桌面》計算機》C:\  搜索mysql,將會找到C:\ProgramData\MySQL\MySQL Server 5.5\data\後綴爲.err的文件爲MySQL錯誤日誌

[2]、解決方案步驟

(1)MySQL軟件自定義安裝位置爲D:\DevelopSoft\database\MySQL\MySQL5_5_x64\soft,

但是my.ini文件中datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/"依舊爲缺省的路徑;

桌面》計算機》C:\  搜索mysql,將會找到C:\ProgramData\MySQL\MySQL Server 5.5\data。

(2)因此修改my.ini文件中

datadir="D:/DevelopSoft/database/MySQL/MySQL5_5_x64/soft/data/"

(3)桌面》計算機》右鍵 管理》服務和應用程序》服務》選中名稱爲 MySQL》右鍵 啓動(S)

2、1045-Access denied for user 'root'@'localhost'(using password:YES)

[2]、解決方案步驟

(1)D:\DevelopSoft\database\MySQL\MySQL5_5_x64\soft\my.ini》

[mysqld]
#在 [mysqld] 底下添加語句:skip-grant-tables,添加完畢後保存。如果提示不讓修改這個文件,則可將它複製到桌面,再用記事本打開它,添加完畢後,將桌面上的文件複製到原來的地方,複製粘貼時選擇替換目標文件。
#skip-grant-tables作爲啓動參數的作用:MYSQL服務器不加載權限判斷,任何用戶都能訪問數據庫。也就是說,啓用這個參數之後,數據庫的安全性會降低。
skip-grant-tables

(2)WIN+R —>輸入cmd》DOS彈窗》

C:\Users\ljx>mysql -u root -p //這個命令是連接MySQL數據庫服務器的命令;
Enter  passward:直接回車

mysql>use mysql;              //使用數據庫名稱爲mysql,這個數據庫

mysql>select host,user,password from user;    //列表查詢表名爲user,的數據

mysql>delete from user where host='localhost';//刪除表指定行數據

mysql>INSERT INTO `user` VALUES ('%', 'yourUser', 'yourPassword', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, '', '');//用戶表新增一條數據

mysql>INSERT INTO `user` VALUES ('localhost', 'yourUser', 'yourPassword', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, '', '');

mysql>update user set host='localhost' where host='127.0.0.1';//修改用戶表user,的數據

mysql>update user set host='%' where host='::1';

mysql>flush privileges;       //刷新數據庫

  

(3)到這裏修改密碼的工作已經完成。接下來註釋掉在(1)my.ini中添加的語句。

[mysqld]
#在 [mysqld] 底下添加語句:skip-grant-tables,添加完畢後保存。如果提示不讓修改這個文件,則可將它複製到桌面,再用記事本打開它,添加完畢後,將桌面上的文件複製到原來的地方,複製粘貼時選擇替換目標文件。
#skip-grant-tables作爲啓動參數的作用:MYSQL服務器不加載權限判斷,任何用戶都能訪問數據庫。也就是說,啓用這個參數之後,數據庫的安全性會降低。
#skip-grant-tables

(4)重啓MySQL服務器

桌面》計算機》右鍵 管理》服務和應用程序》服務》選中名稱爲 MySQL》右鍵 停止(O)》右鍵 啓動(S)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章