CentOS7編譯安裝MySQL 5.6.28和編譯參數
MySQL 5.5之後的源碼包版本,安裝方式採用CMake工具編譯進行安裝,因此在安裝最新版MySQL之前,需要提前安裝它。CMake是一個跨平台、開源軟體構建系統,用於控制軟體編譯過程及產生獨立的設定檔(makefile或者project),可以在編譯時間選擇CMake編譯器進行安裝需要的軟體。CMake官網https://cmake.org/,目前最新版本是3.4.3。
CMake安裝方法
# wget https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz
# yum install gcc gcc-c++ make automake
# ./bootstrap && make && make install
MySQL 5.6新特性
MySQL官網對MySQL 5.6的介紹:
MySQL5.6是有史以來最好的版本,是世界上最廣為使用的開來源資料庫,它提供了一套新的、先進的功能,使我們能建設的新一代基於網路和嵌入式應用和服務。
MySQL5.6的功能和特性
1、更好的效能和可擴充性
改進InnoDB儲存引擎所帶來更好的交易輸送量
改良的最佳化所帶來更好的查詢執行時間和診斷能力
2、線上DDL /架構操作所帶來更好的應用程式可用性
3、通過Memcached的API以NoSQL訪問InnoDB所帶來的更好的開發速度
4、改進複製技術所帶來的高效能和能自行修複的叢集部署
5、改進的Performance Schema所帶來的更好的偵測和監測能力
6、改進的安全控制,使您部署應用程式時不需擔心
7、其他重要的增強功能
MySQL5.6編譯參數
官方文檔:http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
編譯安裝mysql-5.6.28
step1:建立mysql使用者、組
[root@www ~]# groupadd mysql
[root@www ~]# useradd -r -g mysql mysql
[root@www ~]# id mysql
uid=996(mysql) gid=1000(mysql) groups=1000(mysql)
[root@www ~]# mkdir /usr/local/mysql
[root@www ~]# mkdir /data/mysqldb
step2:安裝必須的軟體包
[root@www src]# yum install gcc gcc-c++ ncurses-devel bison bison-devel
step3:編譯安裝MySQL
1、將下載的mysql源碼包解壓,並進入其解壓目錄下
[root@www mysql-5.6.28]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysqldb \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0
重新cmake需要刪除CMakeCache.txt檔案
[root@www mysql-5.6.28]# gmake
[root@www mysql-5.6.28]# gmake install
[root@www mysql-5.6.28]# ls /usr/local/mysql/
COPYING README data include man scripts sql-bench
INSTALL-BINARY bin docs lib mysql-test share support-files
2、設定MySQL目錄許可權
[root@www mysql-5.6.28]# chown -R root:mysql /usr/local/mysql/
[root@www mysql-5.6.28]# chown -R mysql:mysql /data/mysqldb/
3、安裝系統資料庫
[root@www scripts]# chmod +x mysql_install_db
[root@www scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysqldb --no-defaults --user=mysql
[root@www scripts]# ls /data/mysqldb/
ib_logfile0 ib_logfile1 ibdata1 mysql performance_schema test
4、拷貝設定檔my.cnf
[root@www mysql-5.6.28]# cd support-files/
[root@www support-files]# cp my-default.cnf /etc/my.cnf
[root@www support-files]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysqldb
port = 3306
# server_id = .....
socket = /var/lib/mysql/mysql.sock
5、拷貝啟動指令碼
[root@www support-files]# cp mysql.server /etc/init.d/mysqld
[root@www support-files]# chmod 755 /etc/init.d/mysqld
[root@www support-files]# chkconfig mysqld on
[root@www ~]# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
[root@www ~]# netstat -ntlp |grep mysqld
tcp6 0 0 :::3306 :::* LISTEN 20708/mysqld
6、設定mysql環境變數
[root@www ~]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
[root@www ~]# source /etc/profile
[root@www ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 Source distribution
Copyright (c) 2000, 2015, 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>
7、初始化MySQL及相關安全選項配置
[root@www ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
MySQL最佳化配置
[root@www ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysqldb
port = 3306
socket = /var/lib/mysql/mysql.sock
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 1M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
net_buffer_length = 8K
table_open_cache = 1024
query_cache_size = 32M
thread_cache_size = 8
max_connections = 1000
max_allowed_packet = 4M
tmp_table_size = 16M
thread_concurrency = 8
skip-name-resolve
interactive_timeout = 8
wait_timeout = 8
long_query_time = 2
slow_query_log=on
slow_query_log_file = /data/mysql/mysql.slow
long_query_time = 1
[root@www ~]# systemctl restart mysqld.service
防火牆配置
[root@www ~]# firewall-cmd --permanent --add-port=3306/tcp
[root@www ~]# firewall-cmd --reload
本文永久更新連結地址: