开发者

Installing a MySQL instance (and schema) with C#

开发者 https://www.devze.com 2023-03-27 11:05 出处:网络
I\'m making a program that needs to interact with a MySQL database on the client\'s machine but I don\'t know how to create a MySQL schema (and instance if necessary) on the computer. Since I开发者_Py

I'm making a program that needs to interact with a MySQL database on the client's machine but I don't know how to create a MySQL schema (and instance if necessary) on the computer. Since I开发者_Python百科 can't connect to the database itself because it doesn't exist yet I'm guessing I need to send a message to the command console of the client's computer and hoping he has MySQL in his path so I can execute a create instance if not exist and then create the schema.


No, don't do it that way. Generally with remote installations that require a MySQL database the procedure goes something like this:

  1. Prompt the user during the install for the host and port of the mysql server (if they don't have MySQL installed at all, instruct them on how to do so / where to learn more).
  2. Ask the user if they want to set up the database automatically
    1. If yes, ask for an admin account name and password (one that can execute CREATE DATABASE statements). Run the appropriate CREATE statements from C#. Also, as a security measure, create a user with lesser privileges with permissions to use that database.
    2. If no, tell the user where the .sql file is, instruct them to install it themself, and then ask the user for the user, password, and database name.
  3. Using the host, port, user, password, and database names provided (or created) connect to the database (whose schema should be defined by now) and make sure you can write to it. Insert any installer values, and you're done.

Doing it this way allows the user to use any database they want, on any machine they want, using any level of security they want.

And you don't want to do this via a command line program, you'll want to do this programatically (by connecting to the server using C# and executing the statements directly).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号