MySql ConnectionString without Database name to create a database in c#

c#, database-connection, mysql

Solution

You can optionally omit the `database` parameter in connection string. Doing so, you get a connection to the database server but you are not connected to any specific database.

Part of Example from MySQL documentation:

MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;

//myConnectionString = "server=localhost;uid=root;pwd=12345;database=test;";
myConnectionString = "server=localhost;uid=root;pwd=12345;";

try
{
    conn = new MySql.Data.MySqlClient.MySqlConnection();
    conn.ConnectionString = myConnectionString;
    conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
    MessageBox.Show(ex.Message);
}

But you have to use database name to qualify the table or other object names within your queries.

Example:

select * from so.tbl_so_q23676633;

In the above example, `'so'` is the database qualifier for table `'tbl_so_q23676633'`.

Problem

I have got a situation where i do need to create a database into MYSQL by using the connection string needed to get into mysql server.Till Now i have used connectionstring with database names .So in this situation what will be the connectionstring structure to execute my create database queries into mysql server. I need the Connectionstring for localhost .. Please help me ..

Original source