Connecting to mysql using mysql

There are many ways on how to connect mysql and a application. But in this tutorial, I will show you how you can connect your application to a mysql database using


After downloading and installing the requirements. First you need to make a sample project. Like this one:


If you remember my tutorial on ms sql connecting to, I used the same project. So if you have a copy of that, then make use of it.

Now, go to the parent class. Then click on ‘project’ then ‘add reference’, then select ‘mysql data’:


Note: You have to install first, before you can actually see that is in there.


Now, you’ll need to go to, and find the connection string for mysql.

There are few things that you need to change in the connection string:

Server– this is the name of the mysql server. Usually its called ‘localhost’, if you haven’t edited the default values when you installed wampserver.

Database- this is the actual database that you’re going to manipulate. You can create it by going to http://localhost/phpmyadmin/. But launch wampserver first.

UID- short for user id. This is the username of the one manipulating the database. Again, if you haven’t messed with the installation, and leave those values to its defaults. Then your username should be ‘root’

Password- by default there is no user password. Unless you’ve put it using phpmyadmin.

That’s it, as I have said on my previous post regarding ms sql server. The codes are almost always the same, only the connection string and the namespace changes. If I haven’t mentioned the namespace that you’re gonna be using, this is the complete namespace:

imports Mysql.Data.MysqlClient

And you also have to change the rest. If you have followed my tutorial on ms sql. Then you have to change.

sqlcommand to mysqlcommand, sqlconnection to mysqlconnection, and so on.

Something like this, if I haven’t made my self clear:

Dim con As New MySqlConnection("Server=localhost;Database=testdb;Uid=root;Pwd=;")
Dim cmd As New MySqlCommand

Then you’ll just have to add something like this on your main windows form (the one that is seen by the user )


Don’t forget to inherit from the parent class where all the methods for data manipulation are stored.

That’s all you have to know about mysql connection for beginners.

One thought on “Connecting to mysql using mysql

  1. Pingback: database connection basics part 1 « Data Integrated Entity

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s