Problems with MySql remote access
Top-posted update: apologies for top-posting; the old question is still below for hysterical reasons, but things have changed. This is now more likely a Delphi question than a MySql question.
I find that from the command line I can access a remote MySql database with
mysql.exe -h 192.168.89.128 -u my_user -p
So it looks like I have correctly set up the remote server.
However, when I try it from Delphi with
AdoConnection.LoginPrompt:=False;//dont ask for the login parameters
AdoCon开发者_如何学Cnection.ConnectionString :=
Format(MYSQL_CONNECT_STRING,[ConfigurationForm.GetServerIpAddress() + ':3306',
DataBase,
ConfigurationForm.GetUserName(),
ConfigurationForm.GetPassword()]);
AdoConnection.Connected := True; //open the connection
which gives a ConnectionString of
Driver={MySQL ODBC 5.1 Driver};
Server=192.168.89.128:3306;
Database=mysql;User=my_user;
Password=my_password;Option=3;
I get an exception
"Unknown MySql server host '192.168.89.128:3306' (11004)"
I can has halpz?
Update & answer: just in case anyone googles & finds this.
The problem was with my Connection String.
I was appending the port to the host Server=192.168.89.128:3306;
when I should have specified them separately, i.e Server=192.168.89.128;Port=3306;
, so that my full connection string is
Driver={MySQL ODBC 5.1 Driver};
Server=192.168.89.128;
Port=3306;
Database=mysql;
User=eLogger;
Password=bct_eLogger;
Option=3;
Apologies to those who barked up the wrong tree to try to help me. I hope that this in turn will help some poor Delphi coder. See also http://delphi.about.com/od/mysql/qt/mysqladoconn.htm
Maybe your problem is which you are including the port in the server
property, try rewriting you connection string without the 3306
port because this is the default port for mysql or include that port in the port
property.
something like that
Without Port
Driver={MySQL ODBC 5.1 Driver};Server=192.168.89.128;Database=mysql;User=my_user; Password=my_user;Option=3;
Specifying the TCP/IP port
Driver={MySQL ODBC 5.1 Driver};Server=192.168.89.128;Port=3306;Database=mysql;User=my_user; Password=my_user;Option=3;
Check if port's open
Execute the following command and look for a ":3306" listener (you did not mention UDP/TCP). This will confirm there is something running on the port.
netstat -a -n
Full answer here on checking ports https://serverfault.com/questions/26564/how-to-check-if-a-port-is-blocked-on-windows
精彩评论