in Database, MySql

Hi everybody!  This article will quickly show you how to install both MySql server and client on machines running Ubuntu Linux.

In order to perform this operation you should first of all make sure that the system package index is up to date by issuing the following command in your terminal.

sudo apt-get update

As a second step you have to install the server and client of MySQL, you can install them at the same time using one-liner command by running the following command from the terminal:

sudo apt-get install mysql-server mysql-client

Cool that’s easy !

Usually after the installation, Ubuntu starts MySQL automatically. To check that, you have several ways, but I really prefer the one by checking the service status using this command.

sudo service mysql status
mysql start/running, process 1147

or this geekiest way by checking for open ports using netstat command.  (You should know that MySQL uses tcp port 3306 by default)

netstat -ntlp | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1208/mysqld

Something wrong, Mysql doesn’t start ?

If MySQL service doesn’t start, you can start it manually by typing the following command.

sudo service mysql start

or this one :

sudo /etc/init.d/mysql start

Now it’s time to login to MySQL server using the client, but before doing that we should know that MySQL comes with no root password as default, you should think about security !!!
You can set a new root password by following this command.

sudo mysqladmin -u root password YoUR-neW-RoOt-PasSwOrD

Nice ! Let’s finally log in to MySQL.

mysql -u root -h localhost -p

If you want to enable MySQL to start at boot use chkconfig command to enable mysql service during boot time (chkconfig must be installed before)

sudo apt-get install chkconfig
sudo chkconfig mysql on

To disable MySQL from starting during boot time.

sudo apt-get install chkconfig
sudo chkconfig mysql off

Have fun!  I’m looking forward to your feedback and questions.

Write a Comment

Comment

  1. I believe it’s highly recommended to set the password of MySQL admin which is root on Ubuntu, while asked on the installation wizard.