天天看點

阿裡雲linux下修改mysql預設密碼(xampp環境)- 原創mysql遠端連接配接 Host * is not allowed to connect to this MySQL server

1.修改MySQL的登入設定: 

# vi /etc/my.cnf 

在[mysqld]的段中加上一句:skip-grant-tables 

例如: 

[mysqld] 

datadir=/var/lib/mysql 

socket=/var/lib/mysql/mysql.sock 

skip-grant-tables 

儲存并且退出vi。 

阿裡雲linux下修改mysql預設密碼(xampp環境)- 原創mysql遠端連接配接 Host * is not allowed to connect to this MySQL server

2.重新啟動mysqld 

停止 MySQL 資料庫

/opt/lampp/lampp stopmysql

隻啟動 MySQL 資料庫

/opt/lampp/lampp startmysql

Stopping MySQL: [ OK ] 

Starting MySQL: [ OK ] 

3.登入并修改MySQL的root密碼 

# /usr/bin/mysql 

Welcome to the MySQL monitor. Commands end with ; or \g. 

Your MySQL connection id is 3 to server version: 3.23.56 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 

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> UPDATE user SET Password = password ('new-password') WHERE User = 'root' ; 

Query OK, 0 rows affected (0.00 sec) 

Rows matched: 2 Changed: 0 Warnings: 0 

mysql> flush privileges ; 

Query OK, 0 rows affected (0.01 sec) 

mysql> quit 

Bye 

阿裡雲linux下修改mysql預設密碼(xampp環境)- 原創mysql遠端連接配接 Host * is not allowed to connect to this MySQL server

 注意password裡面不要有空格

阿裡雲linux下修改mysql預設密碼(xampp環境)- 原創mysql遠端連接配接 Host * is not allowed to connect to this MySQL server

4.将MySQL的登入設定修改回來 

将剛才在[mysqld]的段中加上的skip-grant-tables删除 

5.重新啟動mysqld 

# /etc/init.d/mysqld restart 

Starting MySQL: [ OK ]

----------------------------------------------------------------------------------------------------------------------------

同時需要支援下mysql遠端連接配接,否則會出現bug:   Host 'XXX' is not allowed to connect to this MySQL server 解決方案/如何開啟MySQL的遠端帳号

解決方案:

如果mysql不支援遠端連接配接,會出現提示:錯誤代碼是1130,ERROR 1130: Host * is not allowed to connect to this MySQL server ,

解決此問題有以下2個方法:

localhost改成%

進入mysql的BIN目錄

 代碼如下

複制代碼

mysql -u root -p

mysql>use mysql;

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

mysql>flush privileges;

具體分析

1、在本機登入mysql後,更改“mysql”資料庫裡的“user”表裡的“host”項,從”localhost”改為'%'。

mysql>

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

   #檢視mysql庫中的user表的host值(即可進行連接配接通路的主機/IP名稱)

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

#修改host值(以通配符%的内容增加主機/IP位址,當然也可以直接增加某個特定IP位址,如果執行update語句時出現ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 錯誤,需要select host from user where user = 'root';

檢視一下host是否已經有了%這個值,如果有了直接執行下面的flush privileges;即可)

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

mysql>quit

另一種方法

如果你使用的是phpmyadmin我們可以登入phpmyadmin然後在權限管理中進入,這裡會看到所有的使用者了,你找到root使用者點選修改,然後把域修改成%号即可了(注意,你必須是root權限使用者登入哦,否則是不可以修改的)

如何聯系我:【萬裡虎】www.bravetiger.cn

【QQ】3396726884 (咨詢問題100元起,幫助解決問題500元起)

【部落格】http://www.cnblogs.com/kenshinobiy/