Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you use dependency on MySqlConnector.net (MIT License) instead of MySql.Data( GPL License) #63

Open
himanshukodwani opened this issue Aug 23, 2020 · 13 comments

Comments

@himanshukodwani
Copy link

MySqlConnector.Net licensing seems to be a better choice for many, also performance-wise it has a slight edge.

@adriancs2
Copy link
Member

Thanks for the info. I'll look into this

@Relax594
Copy link

I'd appreciate this as well.

@adriancs2
Copy link
Member

adriancs2 commented Jan 21, 2021

May I know how do you insert scripts?
The blocks of SQL statements for creating procedures, functions, etc?

In MySql.Data, the code will be something like this:

string text = @"DELIMITER |
CREATE PROCEDURE `proceduresample1`()
    DETERMINISTIC
    COMMENT 'A procedure'
BEGIN
SELECT 'Hello World !';
END |";

using (MySqlConnection conn = new MySqlConnection(ConnectionString))
{
	MySqlScript script = new MySqlScript(conn);
	script.Query = text;
	script.Execute();
}

What is the equivalent of above code if using MySqlConnector.net?

@Relax594
Copy link

I've never done that so far sorry.

@himanshukodwani
Copy link
Author

himanshukodwani commented Jan 21, 2021 via email

@Memnarch
Copy link

Memnarch commented Jan 27, 2021

Can confirm you can just use a MySQLCommand in MySQLConnector to run multiple things. Using it and was looking for a backup-integration into my software and ended up here ;)

In my buildsystem I create different sql files for either full creating of my schema or patching a schema between to versions of my database-schema. I can simply load my file into a string, put it into a MySQLCommand and run it and it'll work as expected running all the create/alter statements in it.

From that discussion, MySQLScript from Oracle sounds like a hack to fix a designflaw in their MySQLCommand o.o

@Flithor
Copy link

Flithor commented Mar 1, 2021

Well, MySqlConnector.Net not support DELIMITER statement, DELIMITER it's only work with MySqlClient:
mysql-net/MySqlConnector#645
So, consider notify user do not use DELIMITER.

Your sql can remove DELIMITER and code will be:

string text = @"DROP PROCEDURE IF EXISTS`proceduresample1`;

-- DELIMITER |
CREATE PROCEDURE `proceduresample1`()
    DETERMINISTIC
    COMMENT 'A procedure'
BEGIN
    SELECT 'Hello World !';
-- END |
END;

CALL proceduresample1;
";

using (MySqlConnection conn = new MySqlConnection(ConnectionString))
using (MySqlCommand cmd = new MySqlCommand(text, conn))
{
    conn.Open();
    Debug.WriteLine(cmd.ExecuteScalar());
    //Output "Hello World !"
}

@JeanRessouche
Copy link

News ?

@JeanRessouche
Copy link

Hi @adriancs2, as i was stuck without it, i made a quick (& maybe dirty) fork supporting it, plus a nuget package.

https://github.com/souchprod/MySqlBackup.Net
https://www.nuget.org/packages/MySqlBackup.NET.MysqlConnector/2.3.4.2

It was mostly about changing the reference to MysqlConnector & using a clone of MysqlScript.
Let me know if you want a PR or if you prefer to implement it yourself your own way.
Once implemented, i will remove my package from Nuget.

@adriancs2
Copy link
Member

adriancs2 commented Sep 22, 2021

Hi @souchprod , nice work :)
I have included the 2 additional files ( MySqlScript.cs and MySqlTokenizer.cs ) that done by you and built the DLL. Nice workaround. and thanks.

along with additional for support of MySqlConnector.DLL, I have also added some updates, here are the summary:

[New]

  • ExportInformation.EnableComment = true. (new option)
  • Added support for MySqlConnector (MIT)
  • ExportToFile(), if the directory is not existed. MySqlBackup will attempt to create it.

[Improve]

  • ImportInfo.ErrorLogFile = true. Now will include the query that causes the error.
  • ExportToFile = Auto created directory if not exists.
  • For non delimeter changed query execution, using MySqlCommand in stead of MySqlScript, slightly increase overall import speed.
  • Minor clean up.

I did some benchmark between MySqlCommand and MySqlScript, and I found that MySqlCommand is slightly faster than MySqlScript. Therefore, for normal execution, I use MySqlCommand, and for routines creation (store procedures, functions, views, triggers, etc...), I use MySqlScript.

Below is the summary of the benchmark:

Database Size: 380MB
CPU: Intel Core i5
RAM: 12GB
Harddisk: Samsung SSD Evo 860

Time(Avr)   Class - DLL
---         ---
57s         mysql.exe (MySqlWorkbench)
1m 5s       MySqlCommand - MySql.Data.DLL
1m 5s       MySqlCommand - MySqlConnector.DLL
1m 5s       MySqlCommand - Devart.Express.MySql.DLL
1m 16s      MySqlScript  - MySql.Data.DLL

I have already released the binaries for MySqlConnector.DLL. You can download it at:
https://github.com/MySqlBackupNET/MySqlBackup.Net/releases

You can also download the specific files here for testing:
MySqlBackupNet.MySqlConnector.DLL(2.3.5).zip

@himanshukodwani
Copy link
Author

himanshukodwani commented Sep 22, 2021 via email

@adriancs2
Copy link
Member

Hi @souchprod I would like to upload the new nuget package for MySqlConnector, can you add me as the owner of the package?
https://www.nuget.org/packages/MySqlBackup.NET.MysqlConnector/

@JeanRessouche
Copy link

HI @adriancs2 , yep i'll search how to do this now, nice to have the changes included in the original repo and glad to see the other improvements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants