If you’re a developer who likes to use the Windows platform when building software, you’ll no doubt be using MySQL at some point along the way and an IDE such as Eclipse, NetBeans or something else. For the more basic activities you’ll be doing within your application when interacting with your MySQL database, there will be nothing much to worry about. Whereas with other work you’ll be doing, it is essential to take a backup of your MySQL database with ease, to make sure that you don’t lose all of your test data in the database when you make a mistake in one of your SQL commands.
When you installed MySQL in the first place, you’ll likely have installed this somewhere such as;
C:\Program Files\MySQL\MySQL Server x.x
So open command prompt and navigate to the folder that your MySQL version is installed in, then inside the bin folder;
CD C:\Program Files\MySQL\MySQL Server x.x\bin
Next you need to run the following command. Make sure you personalise the details according to the database you created in the first instance;
Mysqldump –u yourusername –p databasename > C:\Users\YourUsername\databasebackup.sql
Note, if you try to save the file to C:\ for example, then this will result in an access denied error message. The reason for this is because you need Administrator privileges to do this, just like when you’re installing a new piece of software. So instead, make sure you save the file within your current user account that you are logged into Windows with.
Then if you ever need to restore the database, run the following command;
mysql -u yourusername -p databasename < C:\Users\YourUsername\databasebackup.sql
Simples. Yet often can be a little more challenging in practice depending on the details you have configured. Hope this is a useful starting point for when you need to do this.
Latest posts by Michael Cropper (see all)
- How to Convert an SVG to a PNG in Java - February 16, 2020
- How to Setup an Apache Tomcat Environment for Java on AWS Using EC2 in 15 Minutes - February 8, 2020
- How to Create and Run a Basic HelloWorld Java Class - January 24, 2020