How to Install MySQL Server Ubuntu


It is an easy task to install MySQL Server on Ubuntu or Debian linux.

This article explains how to install MySQL Server and its Client packages on a Ubuntu / Debian system. At the time of writing this article the latest version of MySQL Server is 5.5.28

We are going to install MySQL using two methods
1. Installing the binary packages using apt-get method
2. Compiling the packages from source

Method 1 Installing from binary packages

Step 1 Open a terminal to run commands

Step 2 Make sure your package management tools are up-to-date. Run following commands to update the package management

sudo apt-get update

Step 3 Run following command to install MySQL server and client packages

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

When done, you have a MySQL database ready.

You need to set a root password. MySQL has it’s own user accounts, which are not related to the user accounts on your Linux machine. By default, the root account of the MySQL Server is empty. You need to set it. Please replace ‘mypassword’ with your actual password and myhostname with your actual hostname.

sudo mysqladmin -u root -h localhost password 'mypassword'
sudo mysqladmin -u root -h myhostname password 'mypassword'

Method 2 Installing from source packages

Step 1 Open a terminal to run commands

Step 2 Make sure your package management tools are up-to-date. Run following commands to update the package management and install the tools need to build MySQL from source

sudo apt-get -y install build-essential cmake g++ libncurses5-dev bison libaio-dev

Step 3 Downloading and Extracting the package
We will be downloading the package to /usr/local folder

cd /usr/local
sudo wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28-linux2.6-i686.tar.gz
sudo tar zxvf mysql-5.5.28-linux2.6-i686.tar.gz
sudo ln -s mysql-5.5.28-linux2.6-i686 mysql

Step 4 Creating a user and group requires for MySQL

sudo groupadd mysql
sudo useradd -g mysql mysql

Step 5 Assigning proper permission to MySQL server directory

cd /usr/local/mysql
sudo chown -R mysql .
sudo chgrp -R mysql .

Step 6 Installing a sample database and starting a server

cd /usr/local/mysql
sudo scripts/mysql_install_db --user=mysql
sudo chown -R root .
sudo chown -R mysql data
sudo bin/mysqld_safe --user=mysql &

If everything goes well, you should have a MySQL instance running now. To check the same run following command

ps auxwww | grep mysql

Output would be

root@vidyadhar:/usr/local/mysql# ps auxwww | grep mysql
root     13946  0.2  0.0   2216   612 pts/0    S    17:19   0:00 /bin/sh bin/mysqld_safe --user=mysql
mysql    14010  3.1  2.3 293484 35096 pts/0    Sl   17:19   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/vidyadhar.err --pid-file=/usr/local/mysql/data/vidyadhar.pid

When done, you have a MySQL database ready.

Step 7 You need to set a root password. MySQL has it’s own user accounts, which are not related to the user accounts on your Linux machine. By default, the root account of the MySQL Server is empty. You need to set it. Please replace ‘mypassword’ with your actual password and myhostname with your actual hostname.

sudo /usr/local/mysql/mysqladmin -u root -h localhost password 'mypassword'
sudo /usr/local/mysql/mysqladmin -u root -h myhostname password 'mypassword'

Step 8 If you want MySQL to start automatically with every system restart, add the following lines to /etc/rc.local

/usr/local/mysql/support-files/mysql.server start

For basic commands refter this article MySQL Basic

Leave a Reply

rss twitter facbook

Categories

Archives