安装环境:Centos 6.8,MysqL 5.6.23
一、编译安装MysqL前准备工作
安装编译源码所需的工具和库
yum-yinstallgccgcc-c++ncurses-develperlopenssl-develbison
安装cmake(记得好像从MysqL 5.5开始需要cmake编译安装),可从https://cmake.org/download/中下载。
tarzxvfcmake-3.4.1.tar.gz cdcmake-3.4.1 ./bootstrap make&&makeinstall
groupadd-rMysqL useradd-r-gMysqLMysqL
新建MysqL所需目录
mkdir-p/usr/local/MysqL mkdir-p/data/MysqLdb
数据库文件目录创建可参照http://www.jb51.cc/article/p-ebhulbia-ou.html创建LVM并挂载。
三、编译安装MysqL
可从http://dev.mysql.com/downloads/mysql/下载MysqL源码。
tarzxvfMysqL-5.6.23.tar.gz cdMysqL-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&&makeinstall
-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位置 |
cd/usr/local/MysqL chown-RMysqL:MysqL. cd/data/MysqLdb chown-RMysqL:MysqL.
cd/usr/local/MysqL ./scripts/MysqL_install_db--user=MysqL--datadir=/data/MysqLdb
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 #DATASTORAGE# datadir=/data/MysqLdb/ #BINARYLOGGING# 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 #CACHESANDLIMITS# 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
cpsupport-files/MysqL.server/etc/init.d/MysqLd vim/etc/profile.d/MysqL.sh PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib:$PATH exportPATH source/etc/profile.d/MysqL.sh
serviceMysqLdstart chkconfigMysqLdon
dropuser''@localhost; dropuser''@hostname; updateMysqL.usersetpassword=password('*******'); flushprivileges;
至此,MysqL编译安装完成。