Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to do database programming in C++ connecting to some database on Ubuntu 12.04 LTS.

Do I need to install a database before programming in C++ or does any database gets installed with Ubuntu? If not, may I ask the instructions to install (e.g sqlite or whichever is the easiest db to install)

Any help on this would be great.

Thanks in advance.

share|improve this question

No database is installed by default.

You need to install something like MySQL or Oracle or Postgres.

Installing MySql on Ubuntu

Open a terminal window, and use the following command:

sudo apt-get install mysql-server

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


You can edit the /etc/mysql/my.cnf file to configure the basic settings -- log file, port number, etc. For example, to configure MySQL to listen for connections from network hosts, change the bind_address directive to the server's IP address:

bind-address =

Replace with the appropriate address.

After making a change to /etc/mysql/my.cnf the mysql daemon will need to be restarted:

sudo /etc/init.d/mysql restart

If you are running PHP you will also need to install the php module for mysql 5:

sudo apt-get install php5-mysql

To create a new database, use the mysqladmin command:

mysqladmin create

Installing Oracle 10g XE on Ubuntu

Oracle provides a debian repository at, containing only Oracle 10g Express Edition (XE) packages. To see these packages, add this line to /etc/apt/sources.list file:

deb unstable main non-free

Next, you will need to add the GPG key.

wget -O- | sudo apt-key add -

sudo apt-get update

To install the XE database server:

apt-get 'oracle-xe-universal' or 'oracle-xe' (Western European support only).

apt-get install oracle-xe-universal

If you only need the XE client, type

apt-get install oracle-xe-client

share|improve this answer
when installing mysql, you mentioned to use the appropriate IP address. How do I get that Server address? Thank you for the detailed instructions. – user1483206 Aug 17 '12 at 14:44
It's your ip address, you can get it with: sudo ifconfig – LnxSlck Aug 17 '12 at 17:48

I don't think you will have to install any database system while programming C++ . But if you want to use some database package in your program, then you will have to. To install mysql (most used and best):

sudo apt-get install mysql-server mysql-client mysql-common

Its also easier to program in C++ for mysql. So I would recommend you to use mysql.
You are now good to go!

mysql-client will allow interaction between you and the database via command-line. But if you just interact using your program, then to install it as it will help in debugging because your program might contain errors and display wrong things but mysql-client is a full-proof thing.

mysql-common will give you some common tools that you might want to use to enhance the ability of mysql.

The IP address for your machine will be "localhost" (without double inverted comma )

share|improve this answer
Do I need to install all the packages you mentioned or just "mysql-server". can you briefly explain the purpose of the mysql-client, and mysql-common? LnxSlck answered how to install but do you know how to get that Server IP address? – user1483206 Aug 17 '12 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.