简体   繁体   English

使用.NET winforms应用程序安装MYSQL

[英]MYSQL installation with a .NET winforms app

I have a C# application that's utilizes MYSQL. 我有一个利用MYSQL的C#应用​​程序。 I'm at a beta release point and need an installation package that includes my application, along with MYSQL. 我正处于测试版发布点,需要一个包含我的应用程序的安装包,以及MYSQL。 So basically, I need to install MYSQL and perform a restore from within my .NET install package. 所以基本上,我需要安装MYSQL并从我的.NET安装包中执行恢复。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Step 1: You're doing it wrong 第1步:你做错了

You're attempting to install the mysql server . 您正在尝试安装mysql 服务器 This should be your first clue that something is wrong. 这应该是你第一个发现错误的线索。 Most server apps are designed to be installed on servers, not on clients. 大多数服务器应用程序都设计为安装在服务器上,而不是客户端上。 The notable point in this is that server apps like to assume that they 'own' the server. 值得注意的是,服务器应用程序喜欢假设他们拥有“服务器”。 This is a giant no-no for client apps. 对于客户端应用程序来说,这是一个巨大的禁忌。

Step 2: Make a decision, now that we are properly informed 第2步:做出决定,现在我们得到了适当的通知

Now that we've established that we're doing it wrong, we need to choose what to do. 现在我们已经确定我们做错了,我们需要选择做什么。 We have 2 options: 我们有两个选择:

  1. Switch away from MySQL to a 'client' database such as SQLite or SQL Server Compact Edition. 从MySQL切换到“客户端”数据库,如SQLite或SQL Server Compact Edition。
  2. Hack around the problems of installing the server app. 解决安装服务器应用程序的问题。

I personally would recommend switching to SQLite (or similar) as soon as possible. 我个人会建议尽快切换到SQLite(或类似)。 It's the "right thing" to do, and you won't have to be maintaining hacks for years to come. 这是“正确的事情”,你不必在未来几年内维持黑客行为。

Step 3: You'll want to hack MySQL anyway because it probably seems easier. 第3步:无论如何你都想破解MySQL,因为它似乎更容易。

You have been warned. 你被警告了。 Here are some of the things you will need to be aware of, and mitigate: 以下是您需要注意和缓解的一些事项:

  1. MySQL wants to install into program files\\mysql. MySQL想要安装到程序文件\\ mysql中。 If the user already has MySQL installed themselves. 如果用户已经安装了MySQL。 You'll break everything 你会破坏一切
    • You'll need to tell your version of MySQL to install into a custom folder. 您需要告诉您的MySQL版本安装到自定义文件夹中。 I'd recommend it as a subfolder of your application 我推荐它作为您应用程序的子文件夹
  2. MySQL wants to run as a service (and the service will likely be called 'mysql'). MySQL希望作为服务运行(该服务可能被称为'mysql')。 Again if the user already has mysql, you'll break everything. 再次,如果用户已经有mysql,你将打破一切。
    • You'll need to run your service under a different name 您需要以不同的名称运行您的服务
  3. The MySQL server will likely want to write files to Program Files\\etc. MySQL服务器可能希望将文件写入Program Files \\ etc.
    • You'll need to change it's configuration so it writes to %APPDATA% and so on 您需要更改它的配置,以便写入%APPDATA%等等
  4. MySQL will assume it is always being run by the same user. MySQL将假设它始终由同一个用户运行。 If you have 2 users on the machine who want to use your program, you'll need to hack accordingly, by either running MySQL as a local service account (security flaws ahoy), or by installing a seperate mysql for each user. 如果您的计算机上有2个用户想要使用您的程序,那么您需要通过运行MySQL作为本地服务帐户(安全漏洞)来安装,或者为每个用户安装一个单独的mysql。

So with all this in mind, I'd say your best bet is to set up an xcopyable mysql 所以考虑到这一点,我想说你最好的办法是设置一个xcopyable mysql

I've post the answer on another question 我在另一个问题上发布了答案

We took a different approach on this. 我们对此采取了不同的方法。 We make MySQL xcopy-able, by writting a wrapper to generate the configuration file before calling MySQL (to correctly setup the base path and so on). 我们通过在调用MySQL之前编写包装器来生成配置文件(以正确设置基本路径等)来使MySQL xcopy-able成为可能。 Then we have another service installed using the standard setup. 然后我们使用标准设置安装了另一个服务。 This service will take care of starting MySQL and other required background program (in our case Apache) for us. 这项服务将负责为我们启动MySQL和其他所需的后台程序(在我们的例子中为Apache)。 Since the MySQL is deploy by us, we wanted to have full control over it. 由于MySQL由我们部署,我们希望完全控制它。

So with this method, you could simply include the MySQL package along with your installation, and just worried about installing your own service. 因此,使用此方法,您可以简单地包含MySQL软件包以及您的安装,并且只是担心安装自己的服务。

This question is very similar to another question . 这个问题与另一个问题非常相似。 However, the answers don't really help. 但是,答案并没有真正帮助。

You can run executables from a custom action in the .Net deployment project , that's what I'd recommend. 您可以从.Net部署项目中的自定义操作运行可执行文件 ,这就是我建议的。 (Look under the heading "Calling an executable as a custom action") (请在“将可执行文件作为自定义操作调用”标题下查找)

Hopefully everything can be taken care of by via the command line. 希望通过命令行可以处理所有事情。 If not, try a scripted installer like Wise or InstallShield, I think they have better support for stuff like this. 如果没有,尝试像Wise或InstallShield这样的脚本安装程序,我认为他们可以更好地支持这样的东西。

Hope that helps! 希望有所帮助!

If you're using, or can use, NSIS, you should read this: Silent MySQL Install 如果您正在使用或可以使用NSIS,您应该阅读: 无声MySQL安装

Regarding the restore, you might be able to script something up using one of MySQL's included utils or modify part of this old NSIS script 关于还原,您可以使用MySQL包含的utils之一编写脚本或修改此旧NSIS脚本的一部分

Good luck! 祝好运!

@Orion Edwards @Orion Edwards

Thanks a lot for the steps. 非常感谢您的步骤。 I was having the SAME doubt. 我对SAME有疑问。 In fact, We just turned SQLite down because our standalone application needed some procedures and foreign key contraints.But now I feel SQLite is always a better choice for standalone desktop application if it is do be deployed on client machines. 事实上,我们刚刚拒绝了SQLite,因为我们的独立应用程序需要一些程序和外键约束。但是现在我觉得如果将SQLite部署在客户机上,SQLite总是更好的选择。

For now,I have to stick to MySQL. 现在,我必须坚持使用MySQL。 So I'm using different kinds of scripts and mechanisms to handle different possible situations. 所以我使用不同类型的脚本和机制来处理不同的可能情况。 Eg: 例如:

  • If the client machine has no mysql pre-installed, there is a script which completely installs the server and creates the database, users required for my application. 如果客户端计算机没有预安装mysql,则会有一个脚本完全安装服务器并创建数据库,这是我的应用程序所需的用户。
  • If mysql is pre-installed on client machine, I'm asking user for mysql's root username and password and setting up the database & users from within the apllication. 如果客户端机器上预装了mysql,我会询问用户mysql的root用户名和密码,并在apllication中设置数据库和用户。
  • And thirdly, if for some reason client machine had mysql server earlier and then it was uninstalled, since mysql DOES keep track of previous root password even after uninstalling,I run mysql server's .msi, reset the password (manually carry out some steps), and finally create instance of database, all within a script (of course these steps are needed to be carried out by US, not the user as this is a very rare case.) 第三,如果由于某种原因客户端机器早先有mysql服务器然后它被卸载,因为即使卸载后mysql也会跟踪以前的root密码,我运行mysql服务器的.msi,重置密码(手动执行一些步骤),最后在脚本中创建数据库实例(当然这些步骤需要由美国而不是用户执行,因为这是非常罕见的情况。)

Is this approach OK? 这种方法可以吗? Or there is a better,appropriate way to do this? 或者有更好,更合适的方法来做到这一点?

In future I think i'll stick to SQLite ! 将来我想我会坚持SQLite :-p :-P

Have a look at using Visual Studio's package and deployment tool. 看看使用Visual Studio的包和部署工具。 It should automatically bring in the MySQL dependencies if you connect natively (MySQL .NET components) rather than an ODBC connection. 如果您本地连接(MySQL .NET组件)而不是ODBC连接,它应该自动引入MySQL依赖项。 In any case it allows you to add other software to an installation program that can be automatically unpacked if you need it. 在任何情况下,它都允许您将其他软件添加到安装程序中,如果需要,可以自动解压缩。 I have used it to deploy C# apps using the MySQL libraries that you download from MySQL website and for CoreLab's MySQL 3rd party libraries. 我使用它来使用从MySQL网站下载的MySQL库和CoreLab的MySQL第三方库来部署C#应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL在旧的WinForms应用.Net 1.1和ODBC中随机关闭连接 - MySQL randomly closing connections, in old WinForms app .Net 1.1 and ODBC .NET Winforms应用程序中的报告 - Reports in a .NET Winforms App 在VS2013 Professional for C#WinForms应用程序上使用Visual Studio Installer。 使用.NET Framework安装创建安装 - Using Visual Studio Installer on VS2013 Professional for C# WinForms app. create Installation with .NET Framework installation included 将.NET Framework与Winforms应用程序捆绑在一起 - Bundling .NET Framework with Winforms app .NET Winforms应用程序在启动时死机 - .NET Winforms app dies on startup Clickonce部署-安装错误(Winforms .Net 3.5 C#Windows 7) - Clickonce Deployment - installation error (Winforms .Net 3.5 C# Windows 7) 从WinForms应用程序检查.Net框架版本 - Check on .Net framework version from WinForms app Winforms .NET 4.5应用程序在新计算机上崩溃 - Winforms .NET 4.5 app is crashing on a new machine 应用安装的.NET 2.0流程提升 - .NET 2.0 Process Elevation for App Installation C#WinForms - 应用程序安装错误 - 清单中的引用与下载的程序集的标识不匹配 - C# WinForms - App Installation Error - Reference in the manifest does not match the identity of the downloaded assembly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM