Centos6.7 编译安装 MySQL
# 安装依赖包
[root@localhost ~]# yum -y install gcc gcc-c++ autoconf* automake* zlib* libxml* ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bison bison-devel unzip wget # 进入指定目录下载
[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.27.tar.gz # 添加mysql运行账户
[root@localhost ~]# /usr/sbin/groupadd mysql
[root@localhost ~]# /usr/sbin/useradd mysql -g mysql -s /sbin/nologin -M # 解压下载源码包
[root@localhost src]# tar zxvf mysql-5.6..tar.gz
[root@localhost src]# cd mysql-5.6. # 编译三步曲
[root@localhost mysql-5.6.]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_MEMORY_STORAGE_ENGINE= \
-DWITH_READLINE= \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT= \
-DENABLED_LOCAL_INFILE= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci [root@localhost mysql-5.6.]# make && make install # 复制mysql配置文件
[root@localhost mysql-5.6.]# cp -rf support-files/my-default.cnf /etc/my.cnf # 复制myssql启动管理文件
[root@localhost mysql-5.6.]# cp support-files/mysql.server /etc/init.d/mysqld # 赋权限
[root@localhost ~]# chmod /etc/init.d/mysqld # 添加开机启动
[root@localhost ~]# chkconfig --level mysqld on # 创建数据库存放目录
[root@localhost ~]# mkdir -p /data/mysql # 给数据库目录权限赋给mysql用户
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql
[root@localhost ~]# chown -R mysql:mysql /data/mysql [root@localhost ~]# cd /usr/local/mysql
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/sbin/ # 数据库初始化
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql # 启动数据库
[root@localhost ~]# /etc/init.d/mysqld start、 # 对数据账户进行基本安全设置
[root@localhost ~]# mysql_secure_installation
[root@localhost ~]# vi /etc/my.cnf
[client]
port = [mysqld] port =
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links= log_error = /data/mysql/mysql-error.log
slow_query_log =
long_query_time =
slow_query_log_file = /data/mysql/mysql-slow.log character_set_server=utf8 back_log =
max_connections =
max_connect_errors = table_open_cache =
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M read_buffer_size = 2M
read_rnd_buffer_size = 16M sort_buffer_size = 8M
join_buffer_size = 8M thread_cache_size =
thread_concurrency = query_cache_size = 64M
query_cache_limit = 2M ft_min_word_len =
default-storage-engine = MYISAM
thread_stack = 240K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
server-id =
key_buffer_size = 32M
bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads =
myisam_recover innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_write_io_threads =
innodb_read_io_threads =
innodb_thread_concurrency =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout = [mysqldump]
quick
max_allowed_packet = 16M [mysql]
no-auto-rehash [myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M [mysqlhotcopy]
interactive-timeout [mysqld_safe]
open-files-limit =
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
## END ##