

- How to run jdbc program using mysql on mac how to#
- How to run jdbc program using mysql on mac zip file#
- How to run jdbc program using mysql on mac manual#

The TEMP_DIR will be automatically deleted once the backup operation is complete. This dir should be writable by the running program. If no email config is set, then nothing happens after backup.Īnother important config that we set is the TEMP_DIR this is the directory that will be used by the library to temporarily store the generated files while still processing. Since we have supplied complete email credentials as part of the properties used to configure it, the zipped database dump will be sent via email to the configured address. The file is named in the format: randomstring_day_month_year_hour_minute_seconds_database_name_dump.zip
How to run jdbc program using mysql on mac zip file#
It will, therefore, attempt connection using these values alongside the supplied username and password.Īt this point, the library can export our database and generate a zip file containing the SQL dump file. Supplying just these properties will make mysql-backup4j assume that the database is running on localhost at port 3306. We only need to instantiate it and pass it a Java Properties object that has the right configuration properties set: //required properties for exporting of db Properties properties = new Properties() tProperty(MysqlExportService.DB_NAME, "database-name") tProperty(MysqlExportService.DB_USERNAME, "root") tProperty(MysqlExportService.DB_PASSWORD, "root") //properties relating to email config tProperty(MysqlExportService.EMAIL_HOST, "") tProperty(MysqlExportService.EMAIL_PORT, "25") tProperty(MysqlExportService.EMAIL_USERNAME, "mailtrap-username") tProperty(MysqlExportService.EMAIL_PASSWORD, "mailtrap-password") tProperty(MysqlExportService.EMAIL_FROM, tProperty(MysqlExportService.EMAIL_TO, //set the outputs temp dir tProperty(MysqlExportService.TEMP_DIR, new File("external").getPath()) MysqlExportService mysqlExportService = new MysqlExportService(properties) mysqlExportService.export() įrom the snippet above, we created a new Properties object and then added the required properties for the database connection, which are: the database name, username, and password.

Exporting MySQL Database ProgrammaticallyĮxporting a MySQL database programmatically is very straightforward with mysql-backup4j. Let’s add the dependency to our project’s pom.xml: com.smattme mysql-backup4j 1.0.1
How to run jdbc program using mysql on mac manual#
Imagine a scenario in which we have both automated and manual processes of database backup - that’s what we’re about to do. Usually, what makes the process somewhat arduous is if we have to manually trigger the process all the time. Once our app is in production, we can’t afford to not have a timely backup in case of eventualities. In this article, we’re going to be looking at mysql-backup4j, a very flexible Java library that we can use to back-up our database periodically.
How to run jdbc program using mysql on mac how to#
By Seun Matt How to backup your MySQL database programmatically using mysql-backup4j
