革博士程序V1仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 2 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # MySqlBackup.Net
  2. A tool to backup and restore MySQL database in C#/VB.NET/ASP.NET.
  3. Runs on MySql.Data.DLL, MySqlConnector.DLL and Devart.Express.MySql.DLL
  4. ## How to Add This Library into Your Project
  5. Read [this wiki: How to Add This Library into Your Project](https://github.com/MySqlBackupNET/MySqlBackup.Net/wiki/How-to-Add-This-Library-into-Your-Project)
  6. ## Backup ALL Databases in 1 Click
  7. Export all the databases one by one to separate SQL dump files. This a sub-project expansion using MySqlBackup.NET. Read more: [MySqlBackup_All_DB](https://github.com/MySqlBackupNET/MySqlBackup_All_DB)
  8. ## Download
  9. https://github.com/MySqlBackupNET/MySqlBackup.Net/releases
  10. Install via NuGet:
  11. **PM> Install-Package MySqlBackup.NET**
  12. [https://www.nuget.org/packages/MySqlBackup.NET/](https://www.nuget.org/packages/MySqlBackup.NET/)
  13. **PM> Install-Package MySqlBackup.Net.DevartExpress**<br />
  14. [https://www.nuget.org/packages/MySqlBackup.Net.DevartExpress/](https://www.nuget.org/packages/MySqlBackup.Net.DevartExpress/)
  15. **PM> Install-Package MySqlBackup.NET.MySqlConnector**<br />
  16. [https://www.nuget.org/packages/MySqlBackup.NET.MysqlConnector/](https://www.nuget.org/packages/MySqlBackup.NET.MysqlConnector/)
  17. ## Backup/Export a MySQL Database
  18. ```C#
  19. string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
  20. string file = "C:\\backup.sql";
  21. using (MySqlConnection conn = new MySqlConnection(constring))
  22. {
  23. using (MySqlCommand cmd = new MySqlCommand())
  24. {
  25. using (MySqlBackup mb = new MySqlBackup(cmd))
  26. {
  27. cmd.Connection = conn;
  28. conn.Open();
  29. mb.ExportToFile(file);
  30. conn.Close();
  31. }
  32. }
  33. }
  34. ```
  35. ## Import/Restore a MySQL Database
  36. ```C#
  37. string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
  38. string file = "C:\\backup.sql";
  39. using (MySqlConnection conn = new MySqlConnection(constring))
  40. {
  41. using (MySqlCommand cmd = new MySqlCommand())
  42. {
  43. using (MySqlBackup mb = new MySqlBackup(cmd))
  44. {
  45. cmd.Connection = conn;
  46. conn.Open();
  47. mb.ImportFromFile(file);
  48. conn.Close();
  49. }
  50. }
  51. }
  52. ```
  53. ## Introduction
  54. MySqlBackup.NET is a tool (DLL) that can backup/restore MySQL database in .NET Programming Language. It is an alternative to MySqlDump.
  55. This tool is developed in C# but able to be used in any .NET Language (i.e. VB.NET, F#, etc.).
  56. Another benefit of making this tool is, we don't have to rely on two small programs - MySqlDump.exe and MySql.exe to perform the backup and restore task. We will have better control on the output result in .NET way.
  57. The most common way to backup a MySQL Database is by using MySqlDump and MySQL Workbench.
  58. MySQL Workbench is good for developers, but when comes to the client or end-user, the recommended way is to get every parameter preset and all they need to know is press the big button "Backup" and everything is done. Using MySQL Workbench as a backup tool is not a suitable solution for the client or end-user.
  59. On the other hand, MySqlDump.exe cannot be executed directly from the Web Server. As some providers forbid that, MySqlBackup will be helpful in building a web-based (ASP.NET) backup tool.
  60. ## Features
  61. * Backup and Restore of MySQL Database
  62. * Can be used in any .NET Languages.
  63. * Export/Import to/from MemoryStream
  64. * Conditional Rows Export (Filter Tables or Rows)
  65. * Progress Report is Available for Both Export and Import Task.
  66. * Able to export rows into different modes. (Insert, Insert Ignore, Replace, On Duplicate Key Update, Update)
  67. * Can be used directly in ASP.NET or web services.
  68. ## Prerequisite and Dependencies for Development, Compile and Production Usage
  69. MySqlBackup.NET relies on the following component to work.
  70. <b>Option 1: MySql.Data (Connector/NET)</b>
  71. * [MySQL dot net Connector/Net (MySql.Data.DLL)](http://www.mysql.com/downloads/connector/net/)
  72. * MySql.Data.DLL is developed by Oracle Corporation, licensed under GPL License (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
  73. <b>Option 2: Devart Express (dotConnect)</b>
  74. * [Devart dotConnect for MySQL Express](https://www.devart.com/dotconnect/mysql/)
  75. * For license agreement, please read: [https://www.devart.com/dotconnect/mysql/licensing-faq.html](https://www.devart.com/dotconnect/mysql/licensing-faq.html)
  76. * Devart.Data.DLL
  77. * Devart.Data.MySql.DLL
  78. <b>Option 3: MySqlConnector (MIT)</b>
  79. * [MySqlConnector: High Performance MySQL Library for .NET](https://mysqlconnector.net/)
  80. * Project URL: https://github.com/mysql-net/MySqlConnector
  81. * Licensed under MIT
  82. * MySqlConnector.DLL
  83. ## Reminder
  84. ### Reminder 1
  85. MySqlBackup.NET (or MySqlBackup.DLL) stands on top of MySql.Data.DLL which also stands on top of .NET Framework, which uses UTF8 encoding by default.
  86. If your database involves any UTF8 or Unicode Characters. You must use a MySQL database with default character of **UTF8** while handling Unicode Characters, such as
  87. * Western European specific languages, the character of 'À', 'ë', 'õ', 'Ñ'.
  88. * Russian, Hebrew, India, Arabic, Chinese, Korean, Japanese characters, etc.
  89. You are recommended to apply the connection string option of charset=utf8. Example:
  90. ```
  91. server=localhost;user=root;pwd=mypwd;charset=utf8;
  92. ```
  93. or
  94. ```
  95. server=localhost;user=root;pwd=mypwd;charset=utf8mb4;
  96. ```
  97. ### Reminder 2
  98. (For MySql.Data connector only)
  99. DateTime conversion between MySQL and .NET Framework. In MySQL, there are various of DateTime format, such as null value or Date only data. But, in .NET Framework, there is no null value (or Date only) for DateTime. This error is not caused by MySqlBackup.DLL. MySql.Data.DLL (developed by Oracle) has decided to throw an exception of Data Conversion Error. Therefore, you are strongly recommended to apply the connection string option of **convertzerodatetime=true**. Example:
  100. ```
  101. server=localhost;user=root;pwd=mypwd;charset=utf8;convertzerodatetime=true;
  102. ```
  103. ## Performance Benchmark (MySqlDump vs MySqlBackup.NET)
  104. [Full Report - Wiki Page: Performance Benchmark (MySqlDump vs MySqlBackup.NET)](https://github.com/MySqlBackupNET/MySqlBackup.Net/wiki/Performance-Benchmark-(MySqlDump-vs-MySqlBackup.NET)))
  105. Summary Benchmark Report:
  106. ```
  107. Database Size: 3.5GB (15 million rows)
  108. Process Tools Time
  109. ------- --------- ------
  110. Backup 1 MySqlDump 2m 36s
  111. Backup 2 MySqlDump 2m 33s
  112. Backup 3 MySqlDump 2m 35s
  113. File size:
  114. 4.66 GB (5,008,487,275 bytes)
  115. Backup 4 MySqlBackup.NET 7m 48s
  116. Backup 5 MySqlBackup.NET 7m 46s
  117. Backup 6 MySqlBackup.NET 7m 50s
  118. File size:
  119. 4.59 GB (4,931,743,894 bytes)
  120. Restore 1 MySql.exe 8m 42s
  121. Restore 2 MySql.exe 8m 23s
  122. Restore 3 MySql.exe 8m 57s
  123. Restore 4 MySqlBackup.NET 9m 44s
  124. Restore 5 MySqlBackup.NET 9m 39s
  125. Restore 6 MySqlBackup.NET 9m 39s
  126. ```
  127. ## License
  128. MySqlBackup.Net is licensed under the [The Unlicense](https://github.com/MySqlBackupNET/MySqlBackup.Net/blob/master/LICENSE).