Stand alone web app MySQL issue

I created a test stand alone web app, uploaded it to my server. I used the sample code from the userguide at MySQL — Xojo documentation.
I set the IP to localhost, does not work, then I set the IP to 127.0.0.1, and get the error “Host ‘127.0.0.1’ is not allowed to connect to this MySQL server”. So how am I supposed to connect to my mysql server?
I have no issue at all when using PHP with the same parameter for the database, except I use localhost instead of an ip.

We use this little app to debug such things:

https://www.dropbox.com/s/9xx6bbc53dglfwz/mysql_db_login_test.zip?dl=0

The error: the error "Host ‘127.0.0.1’ is not allowed to connect to this MySQL server is not a Xojo error. Check the DB configuration.

The database is working just fine with PHP, so there is no db issue. Only programs made with Xojo dont work for me.

Hi Guenter,

you already spotted the difference.
Localhost and 127.0.0.1 are NOT the same for the MySQL Server.

Localhost uses a so called socket connection while 127.0.0.1 is a standard IP connection.
If you want to use 127.0.0.1 you have to ensure that networking is enabled in your MySQL Server configuration and that your user is allowed to connect

I first tried localhost, but it wont work also with Xojo (it works fine with PHP on the same server).

I assume you are using linux.

To allow use of 127.0.0.1 you have to edit your /etc/mysql/my.cnf configuration file and set

skip-networking=0 bind-address=0.0.0.0

The bind-address allows you to listen only on a specific IP Address if you want.
After this you have to restart mysql

service mysql restart

Then you have to login into mysql using the mysql command on the server.
You can update the Users privileges like this:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

It is important to use % if you want to be able to login from any machine using networking.

The other way would be to use Socket Connections in Xojo like your PHP Script does.
To use localhost your application has to support connecting via Socket.
If I remember correctly Xojo wants the MySQL Socket to be located at /tmp on Linux and there is no option to configure this.

If the socket is not there on your Server you could create a link to it. I do this in some of my Apps like this:

#If TargetLinux Then Log "Creating temporary socket for mysql (sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock)" Dim sh As New shell sh.Execute("sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock") If sh.ErrorCode <> 0 Then Log "Error: " + Str(sh.ErrorCode) End If #EndIf

Great, thanks. I will try that.