How to connect c# to remote mysql database

In this quick tutorial I’m going to show you how you can connect your c# application to a remote mysql database. There’s no additional coding involve in this tutorial all you need to do is to configure your connection string a little bit and configure the privileges on your mysql database.



  • phpmyadmin



First you have to access your mysql database using phpmyadmin.


Click on the privileges tab then change the host to Any host.



Connection String

Finally you just have to change the server you’re connecting to. This time its not localhost since you’re not connecting to the database on your local computer.

string con_string = "Server=;


In the example above I used the internal ip address. If you don’t know your internal ip address. Just go to cmd and type ipconfig/all and copy the ip version 4 preferred address. Well that’s just internal ip address, which means that only the people who are inside your home network can access. If you want to connect to a remote mysql database you have to determine your external ip address, you can do so by going to But remember that the ip address of the computer you’re trying to access should be static so that you won’t need to change your connection string every time you need to connect to the remote mysql database.

I have written a tutorial before on how to connect to a remote computer. You might want to read it if you don’t know how to configure your router to make remote access possible.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s