mysql5.1之前編譯mysql使用的是make工具,編譯步驟如下:
./configure --prefix=
make &&make install
mysql5.5之後編譯mysql使用的是cmake工具,編譯步驟如下:
cmake .
檢視幫助使用: cmake -LH 或ccmake .
1.建立mysql使用者及安裝依賴軟體包.
[root@mytest2 mnt]# groupadd mysql
[root@mytest2 mnt]# useradd -g mysql -s /sbin/nologin mysql
[root@mytest2 mnt]# id mysql
uid=101(mysql) gid=102(mysql) groups=102(mysql)
安裝mysql依賴的軟體包
yum install gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel zlib bison cmake
到www.mysql.com下載下傳mysql的源碼包.
2.編譯安裝mysql
cd mysql源碼目錄
cmake . -LH
若産生異常,可以删除CMakeCache.txt,重新執行cmake . -LH
[root@mytest2 mysql-5.5.38]# cmake . -LH
-- Running cmake version 2.6.4
-- MySQL 5.5.38
-- Packaging as: mysql-5.5.38-Linux-x86_64
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
Warning: Bison executable not found in PATH
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/mysql-5.5.38
-- Cache values
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
// install prefix
CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql
// Set to true if this is a community build
COMMUNITY_BUILD:BOOL=ON
// Enable profiling
ENABLED_PROFILING:BOOL=ON
// Enable debug sync (debug builds only)
ENABLE_DEBUG_SYNC:BOOL=ON
// Enable gcov (debug, Linux builds only)
ENABLE_GCOV:BOOL=OFF
// Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer), RPM, DEB, SVR4
INSTALL_LAYOUT:STRING=STANDALONE
// default MySQL data directory
MYSQL_DATADIR:PATH=/usr/local/mysql/data
// MySQL maintainer-specific development environment
MYSQL_MAINTAINER_MODE:BOOL=OFF
// PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>
TMPDIR:PATH=P_tmpdir
// Link ARCHIVE statically to the server
WITH_ARCHIVE_STORAGE_ENGINE:BOOL=OFF
// Enable address sanitizer
WITH_ASAN:BOOL=OFF
// Link BLACKHOLE statically to the server
WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=OFF
// Use dbug/safemutex
WITH_DEBUG:BOOL=OFF
// Compile MySQL with embedded server
WITH_EMBEDDED_SERVER:BOOL=OFF
// Options are: none, complex, all
WITH_EXTRA_CHARSETS:STRING=all
// Link FEDERATED statically to the server
WITH_FEDERATED_STORAGE_ENGINE:BOOL=OFF
// Link INNOBASE statically to the server
WITH_INNOBASE_STORAGE_ENGINE:BOOL=ON
// Use bundled libedit
WITH_LIBEDIT:BOOL=ON
// Compile with tcp wrappers support
WITH_LIBWRAP:BOOL=OFF
// Link PARTITION statically to the server
WITH_PARTITION_STORAGE_ENGINE:BOOL=ON
// Link PERFSCHEMA statically to the server
WITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON
// Generate PIC objects
WITH_PIC:BOOL=OFF
// Use bundled readline
WITH_READLINE:BOOL=OFF
// Options are : no, bundled, yes (prefer os library if present otherwise use bundled), system (use os library)
WITH_SSL:STRING=no
// Compile MySQL with unit tests
WITH_UNIT_TESTS:BOOL=ON
// Valgrind instrumentation
WITH_VALGRIND:BOOL=OFF
// Use bundled zlib
WITH_ZLIB:STRING=bundled
[root@mytest2 mysql-5.5.38]#
2.1 執行編譯.
--啟用SSL的編譯---------------------------------------------
cmake . -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql-5.5.38 \
-DMYSQL_DATADIR:PATH=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE:BOOL=ON \
-DWITH_ARCHIVE_STORAGE_ENGINE:BOOL=On \
-DWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=On \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_READLINE:BOOL=On \
-DWITH_SSL:STRING=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP:BOOL=OFF \
-DENABLED_PROFILING:BOOL=ON \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
--不啟用SSL的編譯---------------------------------------------
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB=bundled \
----------------------------------------------------------
2.2初始化mysql.
chown -R root:mysql /usr/local/mysql
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
echo "export PATH=$PATH:/usr/local/mysql/bin;" >/etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
vi /etc/my.cnf,在[mysqld]中增加datadir=/data/mysql 與innodb-file-per-table=1
bin/mysqld_safe --user=mysql &
chkconfig --add mysqld
chkconfig mysqld on
service mysqld status
2.3驗證并删除匿名使用者.
[root@mytest2 mysql]# service mysqld status
MySQL running (1581)[确定]
[root@mytest2 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.38-log Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
| information_schema |
| mysql |
| performance_schema |
| test |
4 rows in set (0.01 sec)
mysql> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host | password |
| root | localhost | |
| root | mytest2 | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | mytest2 | |
6 rows in set (0.01 sec)
mysql> drop user ''@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ''@mytest2;
mysql> drop user 'root'@'::1';
3 rows in set (0.00 sec)
2.4修改權限
[root@localhost sbin]# chown -R root.mysql /usr/local/mysql-5.5.38
[root@localhost sbin]# chown -R mysql.mysql /data/mysql
[root@localhost local]# ln -s mysql-5.5.38 mysql
[root@localhost local]# chown root.mysql mysql
至此mysql安裝完成.
mysql預設配置檔案查找路徑順序如下:
/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
~/.my.cnf
啟動mysql時指定的--default_extra路徑.
異常的處理方法: 錯誤:‘SSL_OP_NO_COMPRESSION’ 未聲明 (在此函數内第一次使用)
1.下載下傳較新的openssl.
2.編譯安裝
./config shared zlib-dynamic --prefix=/usr/local/openssl
3.配置
mv /usr/bin/openssl /usr/bin/openssl_bak
mv /usr/lib/include/openssl /usr/lib/include/openssl_bak
mv /usr/lib/libssl.so /usr/lib/libssl.so_bak
mv /usr/lib64/libssl.so /usr/lib64/libssl.so_bak
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib/libssl.so
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >>/etc/ld.so.conf
ldconfig -v
4.配置完成後,重新編譯mysql即可.