摘要:通常mysql默認安裝出於安全考慮、通常只會讓主機鏈接到mysql、而其餘的機器經過遠程的方式是鏈接不上mysql的。這樣想在別的機器上遠程操做主機的mysql就會denied、固然備份也會被拒絕。記錄一下如何解決mysql支持遠程。java
環境依然是前面的環境、能夠在其餘機器上測試一下是否能遠程鏈接本主機的mysql。我主機的IP是192.168.26.200、mysql用戶是root、密碼是password、鍵入以下命令、並輸入密碼:mysql
mysql–h192.168.26.200 –uroot –psql
會提示:ubuntu
ERROR 2003(HY000): Can't connect to MySQL server on '192.168.26.200' (111)vim
問題就是咱們並無開啓主機、也就是192.168.26.200上的mysql的容許別人遠程的配置。安全
a) 登陸mysql、輸入命令:ide
mysql –uroot –p
b) 輸入密碼:測試
password
c) mysql的相關權限都在mysql這個自帶的database內、查看user表的指定字段編碼
select user,password , host from user where user = 'root'; #會顯示以下 +------+-------------------------------------------+-----------+ | user |password | host | +------+-------------------------------------------+-----------+ | root |*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | localhost | +------+-------------------------------------------+-----------+ 說明root用戶登陸下的mysql只容許localhost鏈接。
a) 修改root用戶下的mysql、便可以指定某些IP可以鏈接、也能夠指定全部的IP能夠鏈接、這裏指定的是所有code
b) 在上面的查看權限界面執行以下語句:
grant allprivileges on *.* to 'root'@'%' identified by 'password'; flushprivileges;
若是咱們想指定IP鏈接、那麼能夠將上面的%換成咱們指定的IP、好比指定192.168.30.253能夠鏈接
grant allprivileges on *.* to 'root'@'192.168.30.253' identified by 'password'; flushprivileges;
修改mysql的配置文件 my.cnf中
vim /etc/mysql/my.cnf bind-address = 127.0.0.1 將 bind-address =127.0.0.1 這一行註釋掉, 即修改成: #bind-address = 127.0.0.1
使用其餘機器遠程登陸試試:
mysql -h192.168.26.200 -uroot –ppassword #顯示以下信息 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 413 Server version: 5.5.35-0ubuntu0.12.04.2(Ubuntu) Copyright (c) 2000, 2011, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarksof their respective owners. Type 'help;' or '\h' for help. Type '\c' toclear the current input statement. mysql> 則登陸成功
修改mysql安裝目錄下的配置文件my.ini。將其中的latin1修改爲utf8
中止:
net stop mysql
啓動:
net start mysql