locked
How to recreate MySql database on deployment RRS feed

  • Question

  • Hello. I'm finishing windows service (using C#) which use MySql database. Now I should create the setup project do deploy that service but I don't know how to recreate MySql database on target machine. When I was using MS SQL Express database I was just include .MDF file to setup package, but it isn't olvious what files I should include in MySql case and how to map them to connection string.  The only idea I have is to write database backup to .SQL file, include it to setup project and then sequentially execute statements from this file on AfterInstall event. But this probably not a good idea I think.

    So, how to recreate MySql database on target machine using.NET setup project? Any help will be much appreciated.

    Wednesday, March 24, 2010 10:21 PM

Answers

  • Ok. I have done it. It is enough simple using MySql connector. Here is a MySqlScript class description which do almost all work.
    • Marked as answer by Shoar Saturday, March 27, 2010 11:13 PM
    Friday, March 26, 2010 6:18 PM

All replies

  • The easyst form (I guess so) it's write an script file for mysqld.exe Something like  IF EXIST DATABASE My_DB DROP ELSE CREATE DATABASE etc..... Then depends on target machine Windows/Linux you just find mysqld.exe in well known location (relative to setup path of MySQL and run the script in non interactive mode - obvious you should somehow pass the username/password for connection to DB)

     

    This is my 2 cents

     

    P.S. You can create small Console app that would do that and receive username/password/script file name as parametrs. Then you have more control and error handling. Just follow the logic - before you create something make sure that it doesn't exist or delete it first.


    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off (c) — Bjarne Stroustrup [http://www2.research.att.com/~bs/bs_faq.html#really-say-that]
    • Proposed as answer by Jasper22 Thursday, March 25, 2010 12:49 PM
    Thursday, March 25, 2010 12:49 PM
  • Thanks for your response. Yes, looks like you way is easiest but, unfortunately, I not very familiar with that script and it will be not very easy for me. Maybe my way from previous post (programmatical restoring from .sql dump) will take less my time.

    Anyway, thanks for your suggestion.

    Friday, March 26, 2010 12:30 AM
  • Ok. I have done it. It is enough simple using MySql connector. Here is a MySqlScript class description which do almost all work.
    • Marked as answer by Shoar Saturday, March 27, 2010 11:13 PM
    Friday, March 26, 2010 6:18 PM