How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »


Using PowerShell to backup your MySQL databases


A few months ago we had to find a way to backup our MySQL databases, both remotely and locally. Instead of trying to find a software that did something similar I decided to write a few lines of code that solved our problem. Why spend time and money evaluating software when can create your own solution to the problem with little to no cost, right ?

The snippet below is fairly simple. The $databases variable holds an array of all the databases you want to dump. You will need to specify the database name, the path you wish to save the backup and the backup filename. I took the liberty of commenting the code in order to make it a bit more clear.

Please keep in mind that this solution uses mysqldump. This executable is usually located under C:\Program Files\MySQL\MySQL Server 5.6\bin, assuming you have MySQL server installed. In addition to mysqldump, since all our Windows servers we have WinRAR installed, this snippet uses WinRAR in order to compress the database files. You can always modify the code either skip the compression or to use .NET’s ZipFile class or 7zip.

This solution still needs some tweaking. For example, creating a temporary file with the passwords and passing it as an argument to mysqldump to avoid the “Specifying a password on the command line should be considered insecure” message, as well as some code cleanup and error catching. Until then, you are free to modify this example to better suit your needs.

If you have any questions feel free to post them in the comment section below.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

4 Responses to Using PowerShell to backup your MySQL databases

  1. Ben says:

    Too bad i gotta list all DB’s manually and change the script every single time a database is created or deleted

    • CooLMinE says:

      This should be used only in cases where you want to backup specific schemas in a database.

      If you want to backup everything you could simply use “mysqldump -u root -p –all-databases”

  2. Matt Ellis says:

    Thanks for the Script, im currently modifying it for our environment. i did have one question though is there a license you have this under? I would like to complete my changes and release it under the MIT License but wanted to ask about that first.

    • CooLMinE says:

      Thank you for your comment Matt, I’m glad you found it useful.

      Currently all the code I publish on this website has no restrictions as far as modifications go. This excludes some open source projects which are usually under the GPL license and is mentioned in the readme file or/and the license.txt file.

      I will keep it in mind to make it a bit more clear now that you mention it.

      As for this script, it falls under the same category as the other ones. In other words, feel free to modify it/use it for whatever purpose you would like (even commercial). No attribution is required.

      Let me know if you have any additional questions.

Leave a Reply

Your email address will not be published. Required fields are marked *