I. Description
I recently came into contact with the mysql database, so I am free to study it. Today I will demonstrate how to install mysql with the source code. If I use the rpm package for installation, I personally feel quite simple.
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Compile and install the MySQL 5.6 script in the source code package
Environment Description:
Operating System: rhel 5.4x86
Mysql version: mysql-5.5.22
Ii. Install cmake (after mysql5.5, It is compiled using cmake)
You can directly edit MySQL before MySQL 5.5. After MySQL, You need to compile it by using cmake. In the appendix, we will introduce how to compile it directly.
Download cmake-2.8.4.tar.gz. I searched for it by Du Niang.
[Root @ node4 ~] # Tar-zxvf cmake-2.8.4.tar.gz [root @ node4 ~] # Cd cmake-2.8.4 [root @ node4 cmake-2.8.4] #./configure -- prefix =/usr/local/cmake ---- Here you can use # gmake & make install
[Root @ node4 cmake-2.8.4] # make [root @ node4 cmake-2.8.4] # make install
Note: configure needs to be compiled to the directory.
3. Create the mysql installation directory and database storage directory
[root@node4 ~]# mkdir -p /opt/mysql5.5[root@node4 ~]# mkdir -p /opt/mysql5.5/data
4. Create mysql users and user groups
[root@node4 ~]# groupadd mysql[root@node4 ~]# useradd -r -g mysql mysql
V. Install mysql
[Root @ node4 ~] # Tar-zxvf mysql-5.5.22.tar.gz [root @ node4 ~] # Cd mysql-5.5.22 ---- the following error occurs during compilation, need ncurses-devel [root @ node4 mysql-5.5.22] #/usr/local/cmake/bin/cmake-DCMAKE_INSTALL_PREFIX =/opt/mysql5.5-DMYSQL_DATADIR =/opt/mysql5.5/data-DDEFAULT_CHARSET utf8-DDEFAULT_COLLATION = utf8_general_ci-DEXTRA_CHARSETS = all-DENABLED_LOCAL_INFILE = 1 -- MySQL 5.5.22 -- cocould NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline. cmake: 83 (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): cmake/readline. cmake: 127 (FIND_CURSES) cmake/readline. cmake: 217 (MYSQL_USE_BUNDLED_LIBEDIT) CMakeLists.txt: 268 (MYSQL_CHECK_READLINE)
-- Refreshing incomplete, errors occurred! ---- Check whether ncurses is installed: [root @ node4 mysql-5.5.22] # rpm-qa | grep necursesncurses-5.5-24.20060715 ---- install ncurses-devel [root @ node4] # rpm-ivh ncurses-devel-5.5-24.20060715.i386.rpm warning: ncurses-devel-5.5-24.20060715.i386.rpm: header V3 DSA signature: NOKEY, key ID 37017186Preparing... ######################################## ### [100%] 1: ncurses-devel ##################################### ###### [100%] ---- Delete Keys [root @ node4 mysql-5.5.22] # find/-name CMakeCache.txt/root/mysql-5.5.22/CMakeCache.txt/root/cmake-2.8.4/CMakeCache.txt/root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt/root/ cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt/root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt/root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt [root @ node4 mysql-5.5.22] Rm/root/mysql-5.5.22/CMakeCache.txt rm: remove regular file '/root/mysql-5.5.22/CMakeCache.txt '? Yes [root @ node4 mysql-5.5.22] # rm/root/cmake-2.8.4/CMakeCache.txt rm: remove regular file '/root/cmake-2.8.4/CMakeCache.txt '? Yes [root @ node4 mysql-5.5.22] # rm/root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt rm: remove regular file '/root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt '? Yes [root @ node4 mysql-5.5.22] # rm/root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt rm: remove regular file '/root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt '? Yes [root @ node4 mysql-5.5.22] # rm/root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt rm: remove regular file '/root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt '? Yes [root @ node4 mysql-5.5.22] # rm/root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt rm: remove regular file '/root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt '? Yes ---- compile again: [root @ node4 mysql-5.5.22] #/usr/local/cmake/bin/cmake-DCMAKE_INSTALL_PREFIX =/opt/mysql5.5-plugin =/opt/mysql5.5/data-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-DEXTRA_CHARSETS = all-DENABLED_LOCAL_INFILE = 1
[Root @ node4 mysql-5.5.22] # make & make install
Note:
-DCMAKE_INSTALL_PREFIX =/usr/local/mysql // installation directory
-DINSTALL_DATADIR =/usr/local/mysql/data // database storage directory
-DDEFAULT_CHARSET = utf8 // use the utf8 character
-DDEFAULT_COLLATION = utf8_general_ci // check the character
-DEXTRA_CHARSETS = all // install all extended character sets
-DENABLED_LOCAL_INFILE = 1 // allow local data import
Note:
During re-compilation, you need to clear the old object file and cache information.
# Make clean
# Rm-f CMakeCache.txt
# Rm-rf/etc/my. cnf
6. Set Directory Permissions
[Root @ node4 ~] # Cd/opt/mysql5.5/[root @ node4 mysql5.5] # chown-R root: mysql. // set the owner of all files in the current directory to root and the group to mysql [root @ node4 mysql5.5] # chown-R mysql: mysql data/
For more details, please continue to read the highlights on the next page: