简体   繁体   中英

remote connection to mysql

i have two machine PC#1 with db mysql and appache and PC#2 with ac# form try to connect to this db

here is my connection string used in PC#2: SERVER=My_public_ip;DATABASE = my_test; UID = root; PASSWORD = xxxx;" SERVER=My_public_ip;DATABASE = my_test; UID = root; PASSWORD = xxxx;"

when i try to connect locally from PC#1 it work good:

SERVER=localhost;DATABASE = my_test; UID = root; PASSWORD = xxxx;"

when i try

i did make my root user remote enabled like that:

GRANT ALL ON *.* to '%'@'%' WITH GRANT OPTION;

and all i get is an Event viewer: unable to connect to any of the specified MySQL host

在此处输入图片说明

If both MySql installation are similar (no port changes etc.) then you might want to check connection restriction to the port that MySQL is listening to (usually 3306) on the remote machine. A firewall or something of that sort may be preventing access.

Also if I may ask, have you used any other tool(like MySQL WorkBench or similar) to connect to the MySQL on the remote machine, from the machine which is running your c# form.

That may give you an idea as to whether it access restrictions.

Lastly, i suggest you specify the port in the connection string.

"Data Source =SomeName; Database=SomeDb; User Id=SomeUserId; Password=SomePassword; Port=3306;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM