Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

c# - remote connection to mysql

i have two machine PC#1 with db mysql and appache and PC#2 with a c# 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;"

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

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...