[SOLVED] Unable to connect to any specified mysql C#

Issue

I can’t connect to my sql server, i tried some fixes from stackoverflow and google and it didn’t help me. Thanks.

  connString = "SERVER ='''myserverip''';PORT=3306;DATABASE=mydatabase;UID=myuser;PASSWORD=mypassword";
        try
         {
             conn = new MySqlConnection();
             conn.ConnectionString = connString;
             conn.Open();
             MessageBox.Show("Connection success");

         }
         catch (MySql.Data.MySqlClient.MySqlException ex)
         {
             MessageBox.Show(ex.Message);
         }

To configure myuser I used this on my linux vps.

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword'; CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword'; GRANT ALL ON *.* TO 'myuser'@'localhost'; GRANT ALL ON *.* TO 'myuser'@'%';

i tried : Unable to connect to any of the specified mysql hosts. C# MySQL ( i tried to use MySqlConnectionStringBuilder, don’t specify the port, instead of password in connection string i typed psw);
Disable my pc firewall, disable linux server firewall

Solution

So, after searching on google how to setup sql connection in linux, and trying different setups hardly I fixed it so I want to share with stackoverflow how I fixed it. Thanks for help @Avo Nappo.

First you need to comment out the line #bind-address from your sql config.
The accepted answer here :MySQL root access from all hosts .

Then I create a user using this command CREATE USER 'golden'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'golden'@'%';

And in c# I used my default connection string that is in the question. I don’t know why but MySqlConnectionStringBuilder dose not work on my pc. I hope this will help someone. Have a nice day and keep coding.

Answered By – Mihaita

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *