Install MySQL 5.6.14 on Ubuntu 12.04 from Source Code
by juniwayOperating System:Ubuntu 12.04 LTS 64 bits
MySQL Version:5.6.14
Installation File type:Source Code, compressed in mysql-5.6.14.tar.gz
Download:http://dev.mysql.com/downloads/mysql/#downloads
Installing MySQL in other versions of ubuntu should be similar or exactly same, like ubuntu 13.04, etc.
In most of occasions, build a tool/software from the source code enables us to access to the latest version and the latest features, and also it enables us to customize build parameters, compiler optimizations, and installation location.
Before you build MySQL from source code, you may be better to check if there is a pre-complied binary package distribution available already because a binary package is usually built with the best possible options for optimal performance, if a binary package distribution is available, you may not need to build MySQL from source code because it can save you a lot of pain.
Here we go, let's start to install MySQL from source code, I break down the procedure to a lot of easy understand steps as following:
Step 1. Get the source code package from the official site,
for ubuntu, the file you get will shoud be mysql-5.6.14.tar.gz
Step 2. You may put it in /tmp or /home/username/Download, but it doesn't matter too much whether you put it here or there, because eventually you need to compile it to binary so that you can install it in a location that you specified.
Step 3. Prerequisite tools to be installed before you are able to compile the MySQL source code files
According to the official documents, to install MySQL from source, your system must have the following tools, regardless of installation method:
- CMake, which is used as the build framework on all platforms. CMake can be downloaded fromhttp://www.cmake.org.
- A good make program. Although some platforms come with their own make implementations, it is highly recommended that you use GNU make 3.75 or newer. It may already be available on your system as gmake. GNUmake is available from http://www.gnu.org/software/make/.
- A working ANSI C++ compiler. GCC 4.2.1 or later, Sun Studio 10 or later, Visual Studio 2008 or later
- Perl is needed if you intend to run test scripts. Most Unix-like systems include Perl. On Windows, you can use a version such as ActiveState Perl.
Step 4. Create user and group.
You need to create a group and a user for MySQL(for ownership only, not for login permission), let's just call the group name and the user name both mysql, you can also choose other names if you like.
sudo groupadd mysql
sudo useradd -r -g mysql mysql
Step 5. Compile the source files and Install
cd /tmp/mysql-5.6.14
cmake .
make
make install
Note: Usually when we install something from source code, we run ./configure first and then make, make install, but as directed by official document, here we run cmake . to do the pre-configuration job.
To prevent old object files or configuration information from being used, run these commands on Unix before re-running CMake:
make clean
rm CMakeCache.txt
To install in a specific directory, add a DESTDIR parameter to the command line:
make install DESTDIR="/opt/mysql"
For more information about CMake, check http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
Step 6. Installation complete
By default, MySQL is installed in /usr/local/mysql directory, if everything goes fine there should be no error messages, make sure you have already installed the dependency library libiao1.
Now we need to configure the MySQL settings after the above installation, we call this step as post installation
Step 1.
cd /usr/local/mysql
chown -R mysql .
shgrp -R mysql .
Step 2.
run the mysql_install_db program to set up the initial MySQL grant tables containing the privileges that determine how users are permitted to connect to the server. You will need to do this if you used a distribution type for which the installation procedure does not run the program for you.
scripts/mysql_install_db --user=mysql
Typically, mysql_install_db needs to be run only the first time you install MySQL, so you can skip this step if you are upgrading an existing installation, However, mysql_install_db does not overwrite any existing privilege tables, so it should be safe to run in any circumstances.
It might be necessary to specify other options such as
--basedir
or --datadir
if mysql_install_db does not identify the correct locations for the installation directory or data directory. For example:scripts/mysql_install_db --user=mysql \
--basedir=/opt/mysql/mysql \
--datadir=/opt/mysql/mysql/data
The mysql_install_db script creates the server's data directory with
Under the data directory, it creates directories for the mysql
as the owner.mysql
database that holds the grant tables and the test
database that you can use to test MySQL. The script also creates privilege table entries for root
and anonymous-user accounts. The accounts have no passwords initially.Step 3.
Most of the MySQL installation can be owned by
root
if you like. The exception is that the data directory must be owned by mysql
. To accomplish this, run the following commands as root
in the installation directory:chown -R root .
chown -R mysql data
If you want MySQL to start automatically when you boot your machine, you can copy
support-files/mysql.server
to the location where your system has its startup files. in ubuntu, it is /etc/init.d
or you can create a symbolic link point to support-files/mysql.server in /etc/init.d
Step 4.
It is important that the MySQL server be run using an unprivileged (non-
root
) login account. To ensure this if you run mysqld_safe as root
, include the --user
option as shown. Otherwise, you should execute the script while logged in as mysql
, in which case you can omit the --user
option from the command.bin/mysqld_safe --user=mysql &
Step 5.
Step 6.
Step 7.
You should be able to see use MySQL now.
Reference: http://dev.mysql.com/doc/refman/5.6/en/index.html
Use mysqladmin to verify that the server is running. The following commands provide simple tests to check whether the server is up and responding to connections:
bin/mysqladmin version
bin/mysqladmin variables
shut down the server and start the server again
bin/mysqladmin -u root shutdown
bin/mysqld_safe --user=mysql &
Step 7.
Run some simple tests to verify that you can retrieve information from the server. The output should be similar to what is shown here:
bin/mysqlshow
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
bin/mysqlshow mysql
Database: mysql +---------------------------+ | Tables | +---------------------------+ | columns_priv | | db | | event | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | plugin | | proc | | procs_priv | | servers | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+
+------+--------+------+ | host | db | user | +------+--------+------+ | % | test | | | % | test_% | | +------+--------+------+bin/mysql -e "SELECT Host, Db, User From db" mysql
You should be able to see use MySQL now.
Reference: http://dev.mysql.com/doc/refman/5.6/en/index.html