遠程連接mysql報錯ERROR 1130: host localhost not allowed to connect to this MySQLserver

1、用root用戶登錄mysql數據庫

(1)停止MySQL服務,執行net stop mysql;

(2)在mysql的安裝路徑下找到配置文件my.ini,

	找到[mysqld]
		  
	輸入:skip-grant-tables,保存

(3)重啓mysql服務,net start mysql;

(4)執行mysql -uroot -p,回車,再回車,即可進入mysql數據庫;

2、本機登入mysql

更改 “mysql” 數據庫裏的 “user” 表裏的 “host” 項,從”localhost”改稱’%’。

mysql>use mysql;

查詢出數據庫的用戶名

mysql>select host,user,password from user;

把用戶表裏面的host項改爲“%”

mysql>update user set host = '%' where user ='root';

mysql>flush privileges;    #刷新用戶權限表

mysql>select host,user,password  from user where user='root';

3、插入本地登錄的用戶

mysql>insert into user values('localhost', 'root', '', '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,'','');

此時本地連接的用戶localhost密碼爲空

4、修改root密碼

用update方式修改root密碼正常

mysql> update user set password=password("123456") where user="root";

mysql>flush privileges; 

5、退出MySQL,

在配置文件中註釋:skip-grant-tables,重啓mysql服務

6、本地重新連接mysql數據庫

輸入修改後的密碼,連接成功

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