Backup MySQL With Powershell

If you are working with MySQL on Windows you probably know about the MySQL Connector/Net .  If you don’t, please read further. MySQL Connector/Net has made working with MySQL Server or MariaDB Server on windows a breeze.  Initially it was commonly used as an interface between .Net Applications and MySQL.  With the advent of Powershell as the defacto scripting language for Windows administrators, the MySQL Connector/Net has become a nice tool to use for automation. In order to use the MySQL Connector/Net with powershell, you will need to download and install version 6.6.6 from the link provided above. You may ask why we are using an older version, the answer is simple, read below.

Starting with version 6.7, Connector/Net will no longer include the MySQL for Visual Studio integration. That functionality is now available in a separate product called MySQL for Visual Studio available using the MySQL Installer for Windows.
So in order to ensure the driver is registered with the .net machine configuration, we will use version 6.6.6 for this tutorial. So without further ado, let’s get started.  The basic workflow of the script is to query the MySQL Server to find the databases then loop through and backup each database into a separate file using MySQLDump. You can obtain a copy of MySQLDump by downloading the zip version of MySQL Community from the MySQL website or the zip version of MariaDB 5/10 from the MariaDB website.

You may note that the powershell script above has reference to EmailAdmin.ps1. That script can be obtained from my previous article on how to Send Email With Powershell.
Did you find this article useful? Why not share it with your friends?

2 thoughts on “Backup MySQL With Powershell

  1. Hi,

    This works perfectly for mysql 5.5 and below. But when run in MySQL 5.6 it throws a warning as below:

    C:\Windows\System32\cmd.exe : Warning: Using a password on the command line interface can be insecure.

    It work be of great help if the script can be updated to to suppress this warning.

Leave a Reply

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