I need to programmatically call mysqldump with certain parameters. I try to use either the
--source-data option or the
There is the following phrase in the documentation:
From MySQL 8.0.26, use
--source-data, and before MySQL 8.0.26, use
In order to use the correct parameter, I need to determine the version of the MySQL client. But here I face an issue. I ran the mysqldump –version command on different servers and found that the version is not formalized, and is output in different formats on different servers.
On one server, I got the following result:
mysqldump Ver 8.0.28-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
And the following on the other server:
mysqldump Ver 10.13 Distrib 5.7.37, for Linux (x86_64)
The format is obviously different. In this case, the version is in different positions. On the first server version is
8.0.28, on the other, it is
5.7.37. Perhaps there are other formats? How do I get the version of the client simply in the
It seems that the regular expression
d*.d*.d* is an appropriate option. But on other hand, it seems like an unreliable solution, since there may be more formats for how to output the MySQL client version.
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
I found three options for how to get the version.
You can find out the version of the installed
sudo apt show mysql-client | grep Version Version: 8.0.29-0ubuntu0.20.04.3
Here the version format is the same for everyone.
The version can be extracted by one line:
sudo apt show mysql-client | grep Version | sed 's/Version: //' | sed 's/-.*//'
The easiest way is to take the version of the
mysql.exe file itself:
more details on how to do it programmatically (c#):
You can simply find out if the command is supported by a given version of the client by executing
mysql --help and check if the desired parameter in output text.