Mysql默認是不可以通過遠程機器訪問的,通過下面的配置可以開啟遠程訪問。
我的Mysql環境是ubuntu+mysql5
1.修改/etc/mysql/my.conf,修改bind-address,指定為本機實際IP地址,你的my.con修改完大概是如下的樣子
[mysqld]
#
# * Basic Settings
#
default-character-set=utf8
default-storage-engine=INNODB
bind-address = 192.168.1.107
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking
2.用root登陸mysql執行如下命令
grant all on sonardb.* to sonar@'%' identified by '123456';
grant all on sonardb.* to sonar@localhost identified by '123456';
sonardb替換為你想訪問的數據庫名,sonar是你的想使用的用戶名,123456替換為你的密碼,這樣就開啟了遠程訪問功能。