Project Description
This is simple wrapper for creating MySQL server for .NET applications. It download mini MySQL Server, extract and run it.


Idea

This is simple and dirty class which:
  • Download and Extract Mini MySQL Portable Server from Uniform Server Project
  • Finds first avaliable port
  • Configure my.cnf
  • Start Server

It also has methods for:
  • Load sql dump into database
  • ExecuteNonQuery
  • Create and drop databases

Only what is needed is path for writeable directory where downloaded package and server files are stored.

Dependencies:
Simple example

class Program
    {
        static void Main(string[] args)
        {
            var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = Path.GetDirectoryName(assemblyLocation);
            if (assemblyDirectory == null)
            {
                Console.WriteLine("Cannot get assembly directory path");
                return;
            }
            var serverPath = Path.Combine(assemblyDirectory, "mysql");

            var mysqlServer = new MySqlServer(serverPath);
            mysqlServer.Start();
            Console.WriteLine("MySQL server started on port {0}", mysqlServer.GetPort());

            const string dbName = "simpletest1";
            mysqlServer.CreateDatabase(dbName);
            Console.WriteLine("Database {0} created", dbName);

            Console.WriteLine("Press any key to stop server\n");
            Console.ReadKey();
            mysqlServer.DropDatabase(dbName);
            Console.WriteLine("Database {0} dropped", dbName);

            mysqlServer.Stop();
            Console.WriteLine("MySQL server stopped");

            Console.WriteLine("Press any key to exit\n");
            Console.ReadKey();
        }
    }

Last edited Mar 1, 2013 at 8:43 AM by Cieszak, version 5