How to install ASP.NET with Mysql in Linux server

You should enable mod_mono in easyapache to enable ASP.NET. However, for using Mysql database with ASP.NET, you need to download and install a connector from Mysql site.

The one you need is Windows Binaries, no installer (ZIP).


cd /usr/local/src/
mkdir asp-connector
cd asp-connector
wget Windows Binaries, no installer (ZIP)
/opt/mono/bin/gacutil -i  /usr/local/src/asp-connector/bin/MySql.Data.dll

Most of you forget the next step and the Mysql connector won’t work.

cd /opt/mono/lib/mono/gac/MySql.Data
chmod 755 MySql.Data.dll

Restart Apache

/etc/rc.d/init.d/httpd restart

Now you should be able to connect to mysql using .aspx scripts

Here is a custom script to check the working.
First Create a mysql database first (using command line)

$ mysql -u root -p

mysql> CREATE DATABASE asptest;
Query OK, 1 row affected (0.10 sec)

mysql> USE asptest;
Database changed

Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO testtable VALUES(null,'Fame');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO testtable VALUES(null,'Clean');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM testtable;
| id | name |
| 1 | Fame |
| 2 | Clean |
2 rows in set (0.00 sec)

mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON asptest.* TO asptest@localhost IDENTIFIED BY 'nogesspassword';
Query OK, 0 rows affected (0.12 sec)

Query OK, 0 rows affected (0.13 sec)

Lets go to the script
Here is it. It will display the contents of the database.

First, create a file called test.aspx in your web directory
Add this code and save it.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en" lang="en">
    <title>ASP test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script runat="server">
    private void Page_Load(Object sender, EventArgs e)
       string connectionString = "Server=localhost;Database=asptest;User ID=asptest;Password=nogesspassword;Pooling=false;";
       MySqlConnection dbcon = new MySqlConnection(connectionString);

       MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM testtable", dbcon);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "result");

       dbcon = null;

       ArtistsControl.DataSource = ds.Tables["result"];


    <asp:DataGrid runat="server" id="ArtistsControl" />


Finally, you need a web.config file, in the same web directory where test.aspx . It should contain the following to enable the MySQL libraries to be loaded:

Add the following to web.config

<add assembly="MySql.Data"/>
<customErrors mode="Off"/>

Now try accessing the file test.aspx using

If you need any help, please let me know.


3 Responses to How to install ASP.NET with Mysql in Linux server (cPanel)


Hi Guys,

Another issue I found is that, When the scripts are under a sub folder. (You will call the script viahttp://domainname/subfolder/test.aspx) the error may come up saying the assembly MySql is not found.

Here is the fix.
copy the MySql.dll file to your home.

Make a directory named bin under your public_html.
copy the MySql.dll file from /opt/mono/lib/mono/gac/MySql.Data/

into the bin directory just created. Now you can have the scripts inside your subfolders too.

Hi Guys,

One more update.

For image to work properly, you need to install libgdiplus.

In Centos 4.5 and above. Install it using yum

yum install libgdiplus.i386
yum install libgdiplus-devel.i386

Restart apache.

Leave a comment

Leave your opinion

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

%d bloggers like this: