1

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.

Jorge Castro
  • 71,754

2 Answers2

0

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

Configuration

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 = 192.168.0.5

Replace 192.168.0.5 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 http://oss.oracle.com/debian, containing only Oracle 10g Express Edition (XE) packages. To see these packages, add this line to /etc/apt/sources.list file:

deb http://oss.oracle.com/debian unstable main non-free

Next, you will need to add the GPG key.

wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -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

LnxSlck
  • 12,256
0

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 )

Pranit Bauva
  • 1,091
  • 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