MySQL Installation on Ubuntu

Note

"sudo" is used during the installation, and hence login to an Ubuntu account with administrator rights

Install MySQL on Ubuntu

  1. Install MySQL package and create a MySQL's root password when promoted
    sh> sudo apt-get install mysql-server
    

    MySQL server will be automatically started after installation

  2. Verify MySQL server is running
    sh> ps -ef | grep mysql
    
    Both mysqld & mysqld_safe should be running
    
  3. Enable access remotely
    sh> sudo vi /etc/mysql/my.cnf
    
    1. Listen to all IP addresses on the machine: comment out bind-address
      # bind-address = 127.0.0.1
      
    2. OR listen to a specific IP address
      bind-address = 192.64.3.1
      
    3. Restart MySQL Server
      sh> sudo /etc/init.d/mysql restart
      

(Optional) Install MySQL Query Browser & Administrator

sh> sudo apt-get install mysql-query-browser

MySQL Security Hardening on Ubuntu

  1. Ensure the data directory owned by mysql (user) mysql (group)
    sh> sudo chown -R mysql /var/lib/mysql
    sh> sudo chgrp -R mysql /var/lib/mysql
    
  2. Remove access by any other accounts on data directory
    sh> sudo chmod -R go-rwx /var/lib/mysql
    
  3. Remove access by any other accounts on server program
    sh> sudo chmod go-rwx /usr/bin/mysqld_safe
    sh> sudo chmod go-rwx /usr/sbin/mysqld
    sh> sudo chmod go-rwx /etc/init.d/mysql
    

Enable Ubuntu's MySQL Account

  1. Prepare a home directory for mysql user
    1. sudo mkdir /home/mysql
    2. sudo chown -R mysql /home/mysql
    3. sudo chgrp -R mysql /home/mysql
  2. In Ubuntu, System -> Administration -> Users and Groups
  3. Select Unlock and authenticate
  4. Click on User MySQL Server
  5. Enter a new password and confirm it
  6. Select Advanced
    1. Put /home/mysql as home directory
    2. Put /bin/bash as Shell

Test MySQL Installation

sh> mysqladmin -u root -p version status
Enter password: Enter the root password created during installation

Output:
...
Uptime:                 6 sec
...