From the archive: first published in February 2012 on my old blog, Tux86’s Web Tech Blog. Versions, links and screenshots are from that time.
Hi everybody! This article quickly shows you how to install both the MySQL server and the client on a machine running Ubuntu Linux.
Install the server and client
First of all, make sure the system package index is up to date by running the following command in your terminal:
sudo apt-get update
Next, install the MySQL server and client. You can install both at once with a single command:
sudo apt-get install mysql-server mysql-client
Cool, that was easy!
Check that MySQL is running
Ubuntu usually starts MySQL automatically after the installation. There are several ways to check it, but the one I prefer is to look at the service status:
sudo service mysql status
mysql start/running, process 1147
Or, the geekier way, check the open ports with the netstat command (MySQL listens on 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 the MySQL service doesn’t start, you can start it manually with this command:
sudo service mysql start
or this one:
sudo /etc/init.d/mysql start
Set a root password and log in
Now it’s time to log in to the MySQL server with the client. But first, you should know that MySQL comes with no root password by default, so think about security! You can set a new root password with 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
Start MySQL at boot
To have MySQL start at boot, enable the mysql service with the chkconfig command (chkconfig must be installed first):
sudo apt-get install chkconfig
sudo chkconfig mysql on
To stop MySQL from starting at boot:
sudo apt-get install chkconfig
sudo chkconfig mysql off
Have fun! I’m looking forward to your feedback and questions.