avatar

Andres Jaimes

Storing MySQL credentials on a file

MySQL allows you to store credentials in a file called ~/.my.cnf. The contents can look like this:

[mysqldump]
user=myuser
password=mypassword

We have to modify the file permissions and give read/write permissions to the owner only:

1chmod 600 …

Common tasks when working with MySQL

How to install MySQL server in Ubuntu

It’s pretty simple:

1sudo apt-get install mysql-server

How to connect to MySQL using Java

This is a useful and simple snippet:

 1import java.sql.Connection;
 2import java.sql.DriverManager;
 3public class Test { …

Create a connection to MySQL in Java

This time we are going to create a basic connection to MySQL in Java and pull some data from it.

// Compile it:
// javac Mysql.java
//
// Try it:
// java -classpath mysql-connector-java-5.1.27-bin.jar:. MySQL

import java.sql.Connection;
import …