Thursday, September 26, 2013

Install MySQL 5.6.14 on Ubuntu 12.04 from Binary package



Operating System:Ubuntu 12.04 LTS 64 bits
MySQL Version:5.6.14
Installation File typeBinary, compressed in mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz
Downloadhttp://fossies.org/linux/misc/mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz/cloc.html

I believe that installing MySQL in other versions of ubuntu should be similar or exactly same, like ubuntu 13.04, etc

The file you download is a compressed package that include all the files that are necessary for the installation, the only thing you need to do is to unzip the files into a location that you want the MySQL be installed in. Remember, these are compiled files and they are different from a source package which requires you to use make command to compile and use make install command to install.

If you install MySQL from source code, the only difference is that you need to compile those source files and use make install to install them as specified in ./configure command before you compile. While in here, you only need to unzip the package to a directory, and the installation is completed after you done that.

1. Unzip mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz into /usr/local/mysql-5.6.14/ directory

sudo tar zxvf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
(Note: after you done the above command, you should be able to see there is mysql-5.6.14 directory in /usr/local)

Next, you probably will need to create a symbolic link to that directory so that you can refer to mysql more easily regardless of its version number, you do like this:

cd /usr/local
ln -s /usr/local/mysql-5.6.14 mysql
(so now you create a symbolic link mysql in /usr/local to point to the /usr/local/mysql-5.6.14 directory)

The /usr/local/mysql-5.6.14 directory after unzip:


2. Create user and group.
you need to create a group and a user for MySQL, let's just call the group name and the user name both mysql

Create group:
sudo groupadd mysql
Create user:
sudo useradd -r -g mysql mysql
(Note: sudo useradd -r -g groupname username, the user mysql is created for the purpose of controlling the right of files, using '-r' will allow this user no need to login)

3. Change the owner of directory /usr/local/mysql-5.6.14/ to the user mysql
sudo chown -R mysql:mysql /usr/local/mysql-5.6.14
4. Install the shared library libaio1
sudo apt-get install libaio1
5. Use mysql_install_db to initialize the authorization table
sudo scripts/mysql_install_db --user=mysql
6. Configure mysql service

(a) Enter /etc/init.d/
cd /etc/init.d
(b) Create a symbolic link to mysql service
sudo ln -s /usr/local/mysql-5.6.14/support-files/mysql.server mysql.server
or you can copy the mysql.server file into the /etc/init.d directory, this directory controls all the services that are need to start at the boot of the operating system.

(c) Change to ownership of mysql service to the user mysql
sudo chown -R mysql:mysql mysql
(d) Start mysql:
sudo /etc/init.d/mysql.server start
7. Check whether mysql service is running or not
ps -aux | grep mysql
8. Check mysql's version, enter /usr/local/mysql
bin/mysqladmin version


As we can see, MySQL is installed successfully.

Now we need to configure MySQL, we call it post-installation

1. create password for the root user of mysql
First, enter mysql's installation directory, mysql is by default installed in /usr/local/mysql :
cd /usr/local/mysql
Then, type in a new password:
./bin/mysqladmin -u root password '123456'
2. Security configuration, including deleting Test database and anonymous operations.
sudo bin/mysql_secure_installation
Then, do instructions as following:
  1. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
  2.       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!  
  3.   
  4. In order to log into MySQL to secure it, we'll need the current  
  5. password for the root user.  If you've just installed MySQL, and  
  6. you haven't set the root password yet, the password will be blank,  
  7. so you should just press enter here.  
  8.   
  9. Enter current password for root (enter for none):   
  10. OK, successfully used password, moving on...  
  11.   
  12. Setting the root password ensures that nobody can log into the MySQL  
  13. root user without the proper authorisation.  
  14.   
  15. You already have a root password set, so you can safely answer 'n'.  
  16.   
  17. Change the root password? [Y/n] 
  18.  ... skipping.  
  19.   
  20. By default, a MySQL installation has an anonymous user, allowing anyone  
  21. to log into MySQL without having to have a user account created for  
  22. them.  This is intended only for testing, and to make the installation  
  23. go a bit smoother.  You should remove them before moving into a  
  24. production environment.  
  25.   
  26. Remove anonymous users? [Y/n] 
  27.  ... Success!  
  28.   
  29. Normally, root should only be allowed to connect from 'localhost'.  This  
  30. ensures that someone cannot guess at the root password from the network.  
  31.   
  32. Disallow root login remotely? [Y/n] y
  33.  ... Success!  
  34.   
  35. By default, MySQL comes with a database named 'test' that anyone can  
  36. access.  This is also intended only for testing, and should be removed  
  37. before moving into a production environment.  
  38.   
  39. Remove test database and access to it? [Y/n] y
  40.  - Dropping test database...  
  41.  ... Success!  
  42.  - Removing privileges on test database...  
  43.  ... Success!  
  44.   
  45. Reloading the privilege tables will ensure that all changes made so far  
  46. will take effect immediately.  
  47.   
  48. Reload privilege tables now? [Y/n] y 
  49.  ... Success!  
  50.   
  51.   
  52.   
  53.   
  54. All done!  If you've completed all of the above steps, your MySQL  
  55. installation should now be secure.  
  56.   
  57. Thanks for using MySQL!  
  58.   
  59.   
  60. Cleaning up...  

3. Configure the startups.
sudo update-rc.d mysql.server defaults
4. Set environment variables.
Add the mysql/bin into system PATH, need to edit /etc/profile:
sudo vim /etc/profile
add the following line into /etc/profile
export PATH="$PATH:/usr/local/mysql/bin"
Or, you can edit a /etc/environment file directly to achieve a system wide effect:
sudo vim/etc/environment
Now, save the file and restart the computer, and then you will be able to use mysql in any directory
Configuration complete. now you can use the new installed mysql!

2 comments: