Centos6.7 编译安装 MySQL教程
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.27.tar.gz [root@localhost src]# cd mysql-5.6.27 # 编译三步曲 [root@localhost mysql-5.6.27]# cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci [root@localhost mysql-5.6.27]# make && make install # 复制mysql配置文件 [root@localhost mysql-5.6.27]# cp -rf support-files/my-default.cnf /etc/my.cnf # 复制myssql启动管理文件 [root@localhost mysql-5.6.27]# cp support-files/mysql.server /etc/init.d/mysqld # 赋权限 [root@localhost ~]# chmod 755 /etc/init.d/mysqld # 添加开机启动 [root@localhost ~]# chkconfig --level 345 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 = 3306 [mysqld] port = 3306 datadir=/data/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log_error = /data/mysql/mysql-error.log slow_query_log = 1 long_query_time = 2 slow_query_log_file = /data/mysql/mysql-slow.log character_set_server=utf8 back_log = 10 max_connections = 500 max_connect_errors = 10 table_open_cache = 2048 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 = 8 thread_concurrency = 8 query_cache_size = 64M query_cache_limit = 2M ft_min_word_len = 4 default-storage-engine = MYISAM thread_stack = 240K transaction_isolation = REPEATABLE-READ tmp_table_size = 64M log-bin=mysql-bin binlog_format=mixed server-id = 1 key_buffer_size = 32M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 2G innodb_data_file_path = ibdata1:10M:autoextend innodb_write_io_threads = 8 innodb_read_io_threads = 8 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 8M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 [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 = 8192 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
## END ##