MySQL剛安裝完只認得的主機是:localhost和127.0.0.1,mysqllocalhost

來源:互聯網
上載者:User

MySQL剛安裝完只認得的主機是:localhost和127.0.0.1,mysqllocalhost

MySQL剛安裝完只認得的主機是:localhost和127.0.0.1,如果你要讓你機上的IP可以正常登入有兩種辦法:
一是對你的IP   172.16.1.10   進行授權
grant   privileges   on   dbname.*   to   "user "@ "172.16.1.10   "   identified   by   "password ";


如果只是你自己用的話就可以這樣寫
grant   all   on   *.*   to   "user "@ "172.16.1.10"   identified   by   "password ";


grant具體的用法你就參考一下mysql的使用者手冊吧,如果這樣不行的話,就只能通過以下方法進行授權了

mysql> use   mysql;
database   changed

mysql> desc user; 查看有多少個欄位
mysql> insert   into   user   values(val1,val2,....);

 

二是就將root使用者設為可以遠程登入,也即是可以從任何機器上登入
mysql> use   mysql;
database   changed
mysql> update   user   set   host= "%"   where   user= "root";


mysql>use mysql
grant   all   on   *.*   to   "root"@"172.30.41.72"   identified   by   "xcfg304";
restart mysql server

 

方法三:直接在mysql的資料庫管理後台執行:
use mysql;
grant   all   on   *.*   to   "root"@"172.30.41.95"   identified   by   "xcfg304";


php串連mysql:我用localhost串連不上資料庫,用127001可以串連上,但是用工具串連可以串連上問是什原因

查看一下system32下的hosts檔案,看是不是把localhost指向到其他地址了
預設只有一條這樣的資訊
localhost 127.0.0.1
 
localhost與127001測試時開啟的網頁不一樣

開啟的是什嗎??

是你機子上別的網址還是?
你在運行輸入 CMD
然後 Ping localhost

看看出現的IP地址是多少

localhost 代表的是本地的意思
一般來說 代表IP地址的話就是127.0.0.1
也就是說 我 ping 127.0.0.1 == ping localhost

127.0.0.1是代表自己機器的迴路地址,無論是否連網,自己機器都是127.0.0.1,127段是保留區段。

localhost與127.0.0.1的關係:
localhost可以看成主機名稱,127--可以看成主機ip,中間曾在一個主機名稱到ip地址的映射!
如果你在mysql中串連資料庫,要用localhost而不能用127.0.0.1。因為mysql中對於使用者的登陸位置是有限定的,具體見mysql資料庫(database名字就是mysql)裡面的user表,裡面存放的ip和存放的網域名稱是不一樣的,mysql進行匹配時不會自動將ip轉換成網域名稱的。你授權一個使用者從這個ip訪問,不等於授權他從這個餘名訪問。
1、mysql -h 127.0.0.1 的時候,使用TCP/IP串連,
mysql server 認為該串連來自於127.0.0.1或者是"localhost.localdomain" 。
2、mysql -h localhost 的時候,是不使用TCP/IP串連的,而使用Unix socket;
此時,mysql server則認為該client是來自"localhost" 。
 

相關文章

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.