本文主要介紹centos下源碼安裝MySQL 5.6的方法,centos的版本為5.8.
1)首先,你需要到MySQL官網下載源碼tar包,點擊MySQL Community Server,選擇Source Code,源碼包不大,只有34M左右。
註:以下操作沒有特殊說明,都是以root賬戶執行。
2)先安裝cmake(mysql5.5以後源碼安裝都得通過cmake編譯)
# yum install cmake
並確保以下兩個包已安裝最新版:
ncurses
ncurses-devel
3)添加MySQL使用者組和使用者
# groupadd mysql# useradd mysql
4)建立MySQL軟體安裝目錄和資料存放目錄
mkdir -p /opt/mysql #MySQL安裝目錄chown -R mysql:mysql /opt/mysqlmkdir -p /data/mysql #MySQL資料存放目錄mkdir -p /data/mysql/data #存放資料mkdir -p /data/mysql/log #存放日誌mkdir -p /data/mysql/tmp #存放臨時檔案chown -R mysql:mysql /data/mysql
5)cmake編譯安裝MySQL
tar zxvf mysql-5.6.13.tar.gzcd mysql-5.6.13cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/opt/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1makemake install
參數說明:
-DCMAKE_INSTALL_PREFIX=/opt/mysql //指定安裝目錄
-DINSTALL_DATADIR=/data/mysql //指定資料存放目錄
-DSYSCONFDIR=/opt/mysql //指定設定檔目錄(本例的設定檔為/opt/mysql/my.cnf)
-DDEFAULT_CHARSET=utf8 //指定字元集
-DDEFAULT_COLLATION=utf8_general_ci //指定校正字元
-DEXTRA_CHARSETS=all //安裝所有擴充字元集
-DENABLED_LOCAL_INFILE=1 //允許從本地匯入資料
上述步驟執行成功後,MySQL軟體已成功安裝至/opt/mysql目錄下。
7)編輯設定檔my.cnf
[client]socket = /opt/mysql/run/mysql.sock[innotop]socket = /opt/mysql/run/mysql.sock[mysql]prompt = \\u@\\d \\r:\\m:\\s>no-auto-rehash[mysqld_safe]pid-file = /opt/mysql/run/mysqld.pid[mysqld]#### Baes dir ####basedir = /opt/mysqldatadir = /data/mysql/datatmpdir = /data/mysql/tmpsocket = /opt/mysql/run/mysql.sock#### Base configure info ####port = 3306skip-name-resolveold_passwords = 0lower_case_table_names = 1open_files_limit = 65535read_rnd_buffer_size = 5Mmax_allowed_packet = 24Mmax_connect_errors = 50000max_connections = 1000max_user_connections = 950 thread_cache_size=64table_open_cache=1024thread_stack=262144wait_timeout=864000#### Log info ####log-error = /data/mysql/log/alert.logslow_query_log=1slow_query_log_file= /data/mysql/log/slow.loglog-slow-admin-statementslong_query_time = 0.1slow_launch_time=1#### Binary log && Relay log ####binlog_format='MIXED'log-bin = /data/mysql/log/mysql-binlog-slave-updates = 1relay-log = /data/mysql/log/mysqld-relay-binrelay-log-index = /data/mysql/log/mysqld-relay-bin.indexmaster-info-file = /data/mysql/log/master.inforelay-log-info-file = /data/mysql/log/relay-log.infomax_binlog_size = 500Mmax_binlog_cache_size = 2G#### query cache ####query_cache_size = 100Mquery_cache_limit = 1Kquery_cache_min_res_unit = 1Kquery_cache_type=2#myisamconcurrent_insert = 2key_buffer_size = 100Msort_buffer_size = 100Kjoin_buffer_size = 100Kread_buffer_size = 1Mmyisam_sort_buffer_size = 100M#innodb plugin#innodbdefault-storage-engine = INNODBinnodb_flush_method = O_DIRECTinnodb_file_per_table = 1innodb_open_files=60000innodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 100innodb_additional_mem_pool_size = 20Minnodb_buffer_pool_size = 16Ginnodb_log_buffer_size= 400Minnodb_log_file_size = 100Minnodb_log_files_in_group = 4innodb_file_io_threads = 4innodb_thread_concurrency = 16innodb_max_dirty_pages_pct = 50transaction-isolation = READ-COMMITTEDinnodb_data_file_path = ibdata1:10G;ibdata2:5G:autoextendinnodb_buffer_pool_instances=4innodb_thread_concurrency=32 ### Server id #### log_bin_trust_function_creators=1 read_only=0 server_id=5
8)建立資料庫
cd /opt/mysql ./scripts/mysql_install_db --user=mysql
上述建庫語句將根據my.cnf裡設定的資料檔案目錄和記錄檔目錄,產生相應的資料檔案和記錄檔,並建立系統資料庫(如mysql,test,information_schema,performance_schema)
9)設定root密碼,建立唯讀帳號
export PATH=$PATH:/opt/mysql/bin mysqladmin -u root password '***'mysql -uroot -proot@(none) 06:08:34>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '***' WITH GRANT OPTION;root@(none) 06:08:44>GRANT SELECT ON *.* TO 'rnd'@'%' IDENTIFIED BY '***';
10)最後,把MySQL加入系統啟動項和開機啟動
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系統啟動chmod 755 /etc/init.d/mysqld #增加執行許可權chkconfig mysqld on #加入開機啟動
這樣,執行service mysqld start即可啟動MySQL了:)。