CentOS 6.8 編譯安裝MySQL 5.6.23
安裝環境:CentOS 6.8,MySQL 5.6.23
一、編譯安裝MySQL前準備工作
安裝編譯源碼所需的工具和庫
yum -y install gcc gcc-c++ ncurses-devel perl openssl-devel bison
安裝cmake(記得好像從mysql 5.5開始需要cmake編譯安裝),可從https://cmake.org/download/ 中下載。
tar zxvfcmake-3.4.1.tar.gz
cd cmake-3.4.1
./bootstrap
make && make install
二、建立使用者及MySQL所需目錄
新增mysql使用者
groupadd -r mysql
useradd -r -g mysql mysql
建立MySQL所需目錄
mkdir -p /usr/local/mysql
mkdir -p /data/mysqldb
三、編譯安裝MySQL
可從http://dev.mysql.com/downloads/mysql/ 下載mysql源碼。
tar zxvf mysql-5.6.23.tar.gz
cd mysql-5.6.23
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_ARCHIVE_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DMYSQL_DATADIR=/data/mysqldb\
-DMYSQL_TCP_PORT=3306\
-DENABLE_DOWNLOADS=1\
-DSYSCONFDIR=/etc\
-DWITH_SSL=system\
-DWITH_ZLIB=system\
-DWITH_LIBWRAP=0
make&& make install
DCMAKE_INSTALL_PREFIX=dir_name |
設定mysql安裝目錄 |
-DDEFAULT_CHARSET=charset_name |
設定伺服器的字元集。預設情況下,MySQL使用latin1的(CP1252西歐)字元集 |
-DDEFAULT_COLLATION=collation_name |
設定伺服器的定序。 |
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 |
儲存引擎選項:MyISAM,MERGE,MEMORY,和CSV引擎是預設編譯到伺服器中,並不需要明確地安裝。 |
-DMYSQL_DATADIR=dir_name |
設定mysql資料庫檔案目錄 |
-DSYSCONFDIR |
設定my.cnf位置 |
修改mysql目錄許可權
cd /usr/local/mysql
chown -R mysql:mysql .
cd /data/mysqldb
chown -R mysql:mysql .
初始化mysql資料庫
cd/usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
編輯MySQL設定檔
mv /etc/my.cnf /etc/my.cnf.bak
編輯my.cnf,my.cnf可在percona官網中及按照自己的情況產生。網址如下:https://tools.percona.com/wizard 。
[mysql]
# CLIENT #
port = 3306
socket = /data/mysqldb/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /data/mysqldb/mysql.sock
pid-file = /data/mysqldb/mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = /data/mysqldb/
# BINARY LOGGING #
log-bin = /data/mysqldb/mysql-bin
expire-logs-days = 14
sync-binlog = 1
# REPLICATION #
skip-slave-start = 1
relay-log = /data/mysqldb/relay-bin
slave-net-timeout = 60
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 4096
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 592M
# LOGGING #
log-error = /data/mysqldb/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /data/mysqldb/mysql-slow.log
複製MySQL開機檔案及其命令加入PATH
cp support-files/mysql.server /etc/init.d/mysqld
vim /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
source /etc/profile.d/mysql.sh
啟動MySQL並增加啟動項
service mysqld start
chkconfig mysqld on
設定MySQL登入許可權
drop user ''@localhost;
drop user ''@hostname;
update mysql.user set password=password('*******');
flush privileges;
至此,MySQL編譯安裝完成。
本文永久更新連結地址: