安裝環境:Centos 6.8,mysql 5.6.23mysql
1、編譯安裝MySQL前準備工做
c++
安裝編譯源碼所需的工具和庫sql
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
2、建立用戶及MySQL所需目錄bootstrap
新增mysql用戶vim
groupadd -r mysql useradd -r -g mysql mysql
新建MySQL所需目錄bash
mkdir -p /usr/local/mysql mkdir -p /data/mysqldb
數據庫文件目錄建立可參照http://zhoufan.blog.51cto.com/4278592/1790308建立LVM並掛載。服務器
3、編譯安裝MySQL
socket
可從http://dev.mysql.com/downloads/mysql/ 下載mysql源碼。ide
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編譯安裝完成。