#wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
gunzip mysql-5.6.25.tar.gz
tar -xvf mysql-5.6.25.tar
cd mysql-5.6.25

#参数参考

/*

-DCMAKE_INSTALL_PREFIX=dir_name
-DINSTALL_BINDIR=dir_name
-DINSTALL_DOCDIR=dir_name
-DINSTALL_DOCREADMEDIR=dir_name
-DINSTALL_INCLUDEDIR=dir_name
-DINSTALL_INFODIR=dir_name
-DINSTALL_LIBDIR=dir_name
-DINSTALL_MANDIR=dir_name
-DINSTALL_MYSQLSHAREDIR=dir_name
-DINSTALL_PLUGINDIR=dir_name
-DINSTALL_SHAREDIR=dir_name
-DINSTALL_SQLBENCHDIR=dir_name
-DINSTALL_SUPPORTFILESDIR=dir_name
-DODBC_INCLUDES=dir_name
-DODBC_LIB_DIR=dir_name
-DSYSCONFDIR=dir_name
-DTMPDIR=dir_name
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DCOMPILATION_COMMENT=string
-DDEFAULT_CHARSET=charset_name
-DDEFAULT_COLLATION=collation_name
-DENABLE_DEBUG_SYNC=bool
-DENABLE_DOWNLOADS=bool
-DENABLE_DTRACE=bool
-DENABLE_GCOV=bool
-DENABLE_GPROF=bool
-DENABLED_LOCAL_INFILE=bool
-DENABLED_PROFILING=bool
-DIGNORE_AIO_CHECK=bool
-DINNODB_PAGE_ATOMIC_REF_COUNT=bool
-DMYSQL_MAINTAINER_MODE=bool
-DOPTIMIZER_TRACE=bool
-DWITH_ASAN=bool
-DWITH_DEBUG=bool
-DWITH_EDITLINE=value
-DWITH_EMBEDDED_SERVER=bool
-DWITH_EMBEDDED_SHARED_LIBRARY=bool
-DWITH_INNODB_MEMCACHED=bool
-DWITH_LIBEVENT=string
-DWITH_LIBEDIT=bool
-DWITH_LIBWRAP=bool  
-DMYSQL_UNIX_ADDR=file_name  [config:--socket]
-DMYSQL_TCP_PORT=port_num [config:--port]
-DMYSQL_DATADIR=dir_name [config:--datadir]
-DINSTALL_SCRIPTDIR=dir_name [mysql_install_db]
-DINSTALL_SBINDIR=dir_name  [Where to install the mysqld server]
-DINSTALL_MYSQLTESTDIR=dir_name [mysql-test]
-DINSTALL_LAYOUT=name [
STANDALONE: Same layout as used for .tar.gz and .zip packages. This is the default.
RPM: Layout similar to RPM packages.
SVR4: Solaris package layout.
DEB: DEB package layout (experimental).
]
*/

/*正式环境:-DWITH_DEBUG=0*/

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/var/lib/mysql \
-DSYSCONFDIR=/etc \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=1

make

make install
cd /usr/local/mysql
#useradd -M -o -r -d /var/lib/mysql -s /bin/bash -c "MySQL Server" -u 27 mysql
chown -R mysql.mysql ../mysql
scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysqlserver
kill -9 `ps aux |grep mysql |awk {'print $2'}`
/etc/init.d/mysqlserver restart
/usr/local/mysql/bin/mysql_secure_installation
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
#./bin/mysqladmin -u root password 'new-password'

#my.cnf 应结合实际环境设定相关参数值[优化是个渐进的过程]

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
basedir=/usr/local/mysql
datadir=/var/lib/mysql
socket=/var/log/mysqld/mysql.sock
user=mysql
character-set-server=utf8
back_log=300
innodb_buffer_pool_size=500M
innodb_lock_wait_timeout=120
join_buffer_size=16M
max_connections=5000
max_heap_table_size=100M
max_allowed_packet=4M
query_cache_size=10M
read_rnd_buffer_size=10M
read_buffer_size=8M
symbolic-links=0
slave-skip-errors=1062
sort_buffer_size=8M
long_query_time=10
tmp_table_size=16M
thread_cache_size=16
explicit_defaults_for_timestamp=true
slow_query_log_file=/var/log/mysqld/mysql-slow.log
#server-id=1
#log-bin=binlog
#binlog_format=MIXED
#binlog-do-db = db1
#replicate-ignore-table= db2.table2
#expire_logs_days=7
[mysqld_safe]
log-error=/var/log/mysqld/mysqld.log
pid-file=/var/log/mysqld/mysqld.pid

#如果将旧版的账户权限表[user,db]导入新的mysql中,务必执行下面的操作

#将更新相关表结构等信息

mysql_upgrade -uroot -p --force

#权限立即生效[重启mysql服务]

FLUSH PRIVILEGES;