环境: centos 6.5 192.168.9.28 4核4G 虚拟机
一. 安装编译源码所需要的工具和库
[root@localhost ~]# yum -y install gcc gcc-c++ make ncurses-devel perl
[root@localhost soft]# ls
cmake-2.8.6.tar.gz mysql-5.6.35.tar.gz
[root@localhost soft]# tar xf cmake-2.8.6.tar.gz -C /usr/src
[root@localhost soft]# cd /usr/src/cmake-2.8.6/
[root@localhost cmake-2.8.6]# ls
bootstrap cmake_uninstall.cmake.in Docs
ChangeLog.manual CompileFlags.cmake doxygen.config
ChangeLog.txt configure Example
cmake.1 Copyright.txt Modules
CMakeCPack.cmake CTestConfig.cmake Readme.txt
CMakeCPackOptions.cmake.in CTestCustom.cmake.in Source
CMakeGraphVizOptions.cmake CTestCustom.ctest.in Templates
CMakeLists.txt DartConfig.cmake Tests
CMakeLogo.gif DartLocal.conf.in Utilities
[root@localhost cmake-2.8.6]# ./bootstrap
[root@localhost cmake-2.8.6]# make && make install
二.设置mysql用户组和用户
[root@localhost cmake-2.8.6]# groupadd mysql
[root@localhost cmake-2.8.6]# useradd -r -g mysql mysql
三. 新建mysql 所需要的数据目录
[root@localhost cmake-2.8.6]# mkdir -p /usr/local/mysql
[root@localhost cmake-2.8.6]# mkdir -p /data/mysqldb
[root@localhost soft]# tar xf mysql-5.6.35.tar.gz -C /usr/src
[root@localhost soft]# cd /usr/src/mysql-5.6.35/
四.编译安装mysql
[root@localhost mysql-5.6.35]# cmake -DCMAK_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -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
[root@localhost mysql-5.6.35]# make && make install
五.修改mysql目录的所有者和属组
[root@localhost mysql-5.6.35]# chown -R mysql.mysql /data/mysqldb/
[root@localhost mysql-5.6.35]# chown -R mysql.mysql /usr/local/mysql/
六. 导入mysql的配置文件,以下myql配置文件根据服务器的配置不同需要做出相应的更改。
也可以启动mysql时,根据错误日志内容做出相应的更改。
[root@localhost etc]# egrep -v "^$|^#" ./my.cnf
[mysqld]
datadir= /data/mysqldb
socket=/usr/local/mysql/mysql.sock
user=mysql
port = 3306
server_id = 11
autocommit = 0
character_set_server=utf8
max_allowed_packet = 52m
max-connections = 1000
interactive_timeout = 1800
wait_timeout = 1800
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
tmp_table_size = 67108864
tmpdir = /tmp
log-bin=mysql-bin
binlog-format = ROW
relay-log = mysql-relay-bin
log-slave-updates = 1
read_only = 0
sync_binlog = 1
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
slave-skip-errors = ddl_exist_errors
relay-log-info-repository = TABLE
relay_log_recovery = 1
master_info_repository = TABLE
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 90
long_query_time = 2
min_examined_row_limit = 100
innodb_page_size = 16384
innodb_buffer_pool_size = 4G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 1
innodb_log_file_size = 4G
innodb_log_buffer_size = 16777216
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_flush_log_at_trx_commit=1
innodb_sort_buffer_size = 67108864
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
七. 初始化数据库
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
八. 复制mysql启动脚本及加入PATH 路径
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
[root@localhost mysql]# source /etc/profile
九 启动myql 并加入开机自启动
[root@localhost mysql]# /etc/init.d/mysqld start
[root@localhost mysql]# netstat -lnpt | grep 3306
tcp 0 0 :::3306 :::* LISTEN 1361/mysqld
注:在启动mysql的时候,可能会遇到mysql 启动报错的问题,查看错误日志报:
Enter password: 输入123456
Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.6.35-log Source distribution
Copyright (c) 2000, 2016, 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>
至此mysql 5.6 安装完毕