Procedure to Install MySQL5.5 from Source Code on CentOS6.3
Here’s the procedure to install MySQL from source code on CentOS. (Updated 2012/11/08)
The installation procedure is documented in the official documentation (English).
・MySQL :: MySQL 5.5 Reference Manual :: 2.10.2 Installing MySQL from a Standard Source Distribution
CentOS5.7 64bit
MySQL5.5.17
First, become root user.
$ su
Create a group and user to start MySQL as a daemon.
# groupadd mysql
# useradd -g mysql -d /usr/local/mysql mysql
# passwd mysql
# cd /usr/local/src
# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.17.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
# tar zxvf mysql-5.5.17.tar.gz
# cd mysql-5.5.17
To build the source code, I looked for configure in the directory but couldn’t find it. Upon investigation, it seems that starting from MySQL 5.5 series, cmake is recommended and configure is no longer available.
Instead, we compile with cmake.
・CentOS yum dag リポジトリの追加方法 | Linux LABS (How to Add CentOS yum dag Repository | Linux LABS)
・MySQL 5.5.9 インストール Linux cmake | Linux LABS (MySQL 5.5.9 Installation Linux cmake | Linux LABS)
If cmake is not installed, install it with yum.
# yum install -y cmake
Next, install MySQL dependency packages with yum.
# yum install -y ncurses-devel
If you don’t install this and run cmake, you’ll get the following error:
- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
If you run cmake again as is, it will just repeat the error display, so delete the MySQL directory once and re-execute.
# rm -fr /usr/local/src/mysql-5.5.17
# cd /usr/local/src
# tar zxvf mysql-5.5.17.tar.gz
# cd mysql-5.5.17
For cmake options, about 2-3 options seem sufficient for a normal installation.
Let’s just check what’s included when cmake is executed with defaults.
・MySQL :: Building MySQL from Source :: 3 MySQL Source-Configuration Options
cmake . \\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \\
-DDEFAULT_CHARSET=utf8 \\
-DWITH_EXTRA_CHARSETS=all \\
-DDEFAULT_COLLATION=utf8_general_ci \\
-DWITH_PIC=1
Note that when you add -DDEFAULT_CHARSET=utf8 as an option in cmake, you also need to add -DDEFAULT_COLLATION=… or it won’t work properly.
make
make install
Installation is now complete.
First, change the directory owner.
・UNIXコマンド [chown] (UNIX Command [chown])
chown -R mysql:mysql /usr/local/mysql
Next, initialize the database.
/usr/local/mysql/scripts/mysql_install_db \\
--user=mysql \\
--basedir=/usr/local/mysql \\
--datadir=/usr/local/mysql/data
If you do other configurations without initializing the database, you’ll get the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Also set up auto-startup.
cp /usr/local/src/mysql-5.5.17/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
Execute the following command to check the status. If it’s on at the expected runlevel, there’s no problem.
# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Modify the startup script according to your execution environment.
vi /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
Copy the configuration file. Edit the configuration file as needed.
cp /usr/local/src/mysql-5.5.17/support-files/my-medium.cnf /etc/my.cnf
This completes the setup.
Start MySQL with the service command and confirm it’s properly installed.
service mysql start
# vi ~/.bashrc
PATH="$PATH":/usr/local/mysql/bin
# source ~/.bashrc
# mysql -V
mysql Ver 14.14 Distrib 5.5.17, for Linux (x86_64) using EditLine wrapper
If you can log in with the following command, the installation was successful.
mysql -u root
While we’re at it, let’s also change the root password.
mysql> set password for root@localhost=password('newpassword');
Query OK, 0 rows affected (0.02 sec)
mysql> \\q
# mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g. ……
This completes the password setup. That’s all for the initial configuration.
When starting MySQL, I got the following error:
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid)
Looking at the processes, it seems to be already running, but I can’t log in with mysql -u root.
It’s a bit rough, but killing the process with the kill command and starting MySQL again worked.
Here’s the procedure:
# ps aux | grep mysql
mysql 32031 0.0 3.1 337520 32944 ? Sl 00:28 0:00 /usr/local/mysql/bin/mysqld --localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.
# kill 32031
# ps aux | grep mysql
# /etc/init.d/mysql start
Starting MySQL....... [ OK ]
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 4
Server version: 5.5.17-log Source distribution
Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.
mysql>
That’s all from the Gemba about installing MySQL 5.5 from source code on CentOS 6.3.