From MySQL to Postgres - Useful commands

This article shows a list of basic commands on MySQL and their corresponding versions for PostgreSQL. Connecting to a database MySQL $ mysql -u root -p Postgres $ su pgsql $ psql Or using a different user: $ psql dbname If you can’t connect because you don’t know what databases are available, try any of these: psql -l psql postgres psql template1 The postgres database is a default database meant for use by users, utilities and third party applications read more.

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: chmod 600 ~/.my.cnf And done. We can now use it: mysqldump mydatabase mysqldump is going to read the credentials from that file.

Common tasks when working with MySQL

How to install MySQL server in Ubuntu It’s pretty simple: sudo apt-get install mysql-server How to connect to MySQL using Java This is a useful and simple snippet: import java.sql.Connection; import java.sql.DriverManager; public class Test { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection c = DriverManager.getConnection( "jdbc:mysql://localhost/?user=root&password="); c.close(); System.out.println("Success"); } catch (Exception e) { e.printStackTrace(); } } } How to connect to MySQL using C# Go to http://www.

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 // // Try it: // java -classpath mysql-connector-java-5.1.27-bin.jar:. MySQL import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class MySQL { public Connection getConnection() throws SQLException { Connection conn = null; Properties p = new Properties(); p.put("user", "username"); p.put("password", "superpassword"); String cs = "jdbc:mysql://localhost/demo"; conn = DriverManager.

How to connect to MySQL from a remote server

In few words, you have to configure MySQL to allow remote connections, create a user for connecting and setup your firewall to allow it. You don’t have to do this if you are only connecting from a local application like WordPress. You need root permissions to perform the following commands.  Configuring MySQL Edit the MySQL configuration file. nano /etc/my.cnf Allow connections from all your network interfaces by commenting out the following line:

1000 song names SQL test data

This time I want to share a 1000 rows SQL table that you can use for text searches. It includes a table with 1 column, 1000 rows song title names. It is plain standard SQL so you can use it with any database manager. Download it here. Hope you find it useful.