Databases

Ubuntu provides two Database servers. They are:

They are available in the main repository. This section explains how to install and configure these database servers.

MySQL

MySQL is a fast, multi-threaded, multi-user, and robust SQL database server. It is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software.

Installation

To install MySQL, run the following command from a terminal prompt:

sudo apt-get install mysql-server mysql-client

Once the installation is complete, the MySQL server should be started automatically. You can run the following command from a terminal prompt to check whether the MySQL server is running:

sudo netstat -tap | grep mysql

When you run this command, you should see the following line or something similar:

tcp        0      0 localhost.localdomain:mysql           *:* LISTEN -

If the server is not running correctly, you can type the following command to start it:

sudo /etc/init.d/mysql restart

Configuration

By default, the administrator password is not set. Once you install MySQL, the first thing you must do is to configure the MySQL administrator password. To do this, run the following commands:

sudo mysqladmin -u root password newrootsqlpassword

sudo mysqladmin -p -u root -h localhost password newrootsqlpassword

You can edit the /etc/mysql/my.cnf file to configure the basic settings -- log file, port number, etc. Refer to /etc/mysql/my.cnf file for more details.

PostgreSQL

PostgreSQL is an object-relational database system that has the features of traditional commercial database systems with enhancements to be found in next-generation DBMS systems.

Installation

To install PostgreSQL, run the following command in the command prompt:

sudo apt-get install postgresql

Once the installation is complete, you should configure the PostgreSQL server based on your needs, although the default configuration is viable.

Configuration

By default, connection via TCP/IP is disabled. PostgreSQL supports multiple client authentication methods. By default, IDENT authentication method is used. Please refer the PostgreSQL Administrator's Guide.

The following discussion assumes that you wish to enable TCP/IP connections and use the MD5 method for client authentication. PostgreSQL configuration files are stored in the /etc/postgresql/<version>/main directory. For example, if you install PostgreSQL 7.4, the configuration files are stored in the /etc/postgresql/7.4/main directory.

[Tip]

To configure ident authentication, add entries to the /etc/postgresql/7.4/main/pg_ident.conf file.

To enable TCP/IP connections, edit the file /etc/postgresql/7.4/main/postgresql.conf

Locate the line #tcpip_socket = false and change it to tcpip_socket = true. You may also edit all other parameters, if you know what you are doing! For details, refer to the configuration file or to the PostgreSQL documentation.

By default, the user credentials are not set for MD5 client authentication. So, first it is necessary to configure the PostgreSQL server to use trust client authentication, connect to the database, configure the password, and revert the configuration back to use MD5 client authentication. To enable trust client authentication, edit the file /etc/postgresql/7.4/main/pg_hba.conf

Comment out all the existing lines which use ident and MD5 client authentication and add the following line:

local   all         postgres                          trust sameuser

Then, run the following command to start the PostgreSQL server:

sudo /etc/init.d/postgresql start

Once the PostgreSQL server is successfully started, run the following command at a terminal prompt to connect to the default PostgreSQL template database

psql -U postgres -d template1

The above command connects to PostgreSQL database template1 as user postgres. Once you connect to the PostgreSQL server, you will be at a SQL prompt. You can run the following SQL command at the psql prompt to configure the password for the user postgres.

template1=# ALTER USER postgres with encrypted password 'your_password';

After configuring the password, edit the file /etc/postgresql/7.4/main/pg_hba.conf to use MD5 authentication:

Comment the recently added trust line and add the following line:

local   all         postgres                          md5 sameuser
[Warning]

The above configuration is not complete by any means. Please refer the PostgreSQL Administrator's Guide to configure more parameters.