1、root使用者登入到mysql資料庫
程式碼示例:
/usr/local/mysql/bin/mysql-uroot-p(輸入密碼進入mysql)
2、進入mysql,輸入:
usemysql;
3、檢視user表的情況
SELECTHost,UserFROMuser;
//指明主機名稱,“%”表示匹配所有字串
4、
UPDATEuserSETHost="%"WHEREUser="root"LIMIT1;
5、輸入如下命令讓剛才設定的命令生效
mysql>flushprivileges;
QueryOK,0rowsaffected(0.00sec)
注意,在mysql命令列形式下一定要輸入";"
按照前面五個步驟完成之後,透過控制檯輸入:
[root@linux~]#mysql-hlocalhost-uroot-p
Enterpassword:
ERROR1045(28000):Accessdeniedforuser"root"@"localhost"(usingpassword:YES)
不讓這麼連線資料庫
原因:是因為host對應的user欄位是空的,我們需要將其改為root即可
mysql>selecthost,userfromuser;
+-----------+------+
|host|user|
|%|root|
|127.0.0.1|root|
|linux||
|linux|root|
|localhost||
5rowsinset(0.00sec)
解決辦法一:
mysql>updateusersetuser="root"wherehost="localhost";
QueryOK,1rowaffected(0.00sec)
Rowsmatched:1Changed:1Warnings:0
解決辦法二:
將localhost改為本機的IP地址,則能夠識別了。
[root@linux~]#mysql-h172.16.42.68-uroot-p
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis157
Serverversion:5.1.66Sourcedistribution
Copyright(c)2000,2012,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrademarksoftheirrespective
owners.
Type"help;"or"\h"forhelp.Type"\c"toclearthecurrentinputstatement.
1、root使用者登入到mysql資料庫
程式碼示例:
/usr/local/mysql/bin/mysql-uroot-p(輸入密碼進入mysql)
2、進入mysql,輸入:
程式碼示例:
usemysql;
3、檢視user表的情況
程式碼示例:
SELECTHost,UserFROMuser;
//指明主機名稱,“%”表示匹配所有字串
4、
程式碼示例:
UPDATEuserSETHost="%"WHEREUser="root"LIMIT1;
5、輸入如下命令讓剛才設定的命令生效
程式碼示例:
mysql>flushprivileges;
QueryOK,0rowsaffected(0.00sec)
注意,在mysql命令列形式下一定要輸入";"
按照前面五個步驟完成之後,透過控制檯輸入:
程式碼示例:
[root@linux~]#mysql-hlocalhost-uroot-p
Enterpassword:
ERROR1045(28000):Accessdeniedforuser"root"@"localhost"(usingpassword:YES)
不讓這麼連線資料庫
原因:是因為host對應的user欄位是空的,我們需要將其改為root即可
程式碼示例:
mysql>selecthost,userfromuser;
+-----------+------+
|host|user|
+-----------+------+
|%|root|
|127.0.0.1|root|
|linux||
|linux|root|
|localhost||
+-----------+------+
5rowsinset(0.00sec)
解決辦法一:
程式碼示例:
mysql>updateusersetuser="root"wherehost="localhost";
QueryOK,1rowaffected(0.00sec)
Rowsmatched:1Changed:1Warnings:0
mysql>flushprivileges;
QueryOK,0rowsaffected(0.00sec)
解決辦法二:
將localhost改為本機的IP地址,則能夠識別了。
程式碼示例:
[root@linux~]#mysql-h172.16.42.68-uroot-p
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis157
Serverversion:5.1.66Sourcedistribution
Copyright(c)2000,2012,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrademarksoftheirrespective
owners.
Type"help;"or"\h"forhelp.Type"\c"toclearthecurrentinputstatement.