## 说明 不同服务器需要改变 server_id ,同一台机器上需要改变 port
1. 关闭防火墙[root@mysql ~]# service iptables status --查看防火墙状态[root@mysql ~]# service iptables stop --关闭防火墙[root@mysql ~]# chkconfig iptables off --永久关闭[root@mysql ~]# vim /etc/sysconfig/selinuxSELINUX=disabled2. 配置sysctl.conf
生产环境下建议根据情况配置,虚拟机安装可以不设置3. 检查操作系统上是否已经安装了mysql,如果有进行卸载
[root@mysql yum.repos.d]# rpm -qa |grep mysql[root@mysql yum.repos.d]# yum remove mysql4. 下载mysql源码包
https://dev.mysql.com/downloads/file/?id=4690125. 添加用户和组
[root@mysql u01]# userdel -r mysql --删除原先的mysql用户 -r会删掉附带的group[root@mysql u01]# groupadd mysql[root@mysql u01]# useradd -d /home/mysql -g mysql -m mysql[root@mysql u01]# passwd mysqlChanging password for user mysql.New password: BAD PASSWORD: it is based on a dictionary wordRetype new password: passwd: all authentication tokens updated successfully.[root@mysql u01]# id mysqluid=500(mysql) gid=500(mysql) groups=500(mysql)6. 配置mysql环境变量
[mysql@mysql ~]$ vim .bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/u01/my3306/binexport PATH[mysql@mysql ~]$ source .bash_profile7. 创建目录及授权
[root@mysql u01]# cd /u01[root@mysql u01]# mkdir -p /u01/my3306/data[root@mysql u01]# mkdir -p /u01/my3306/log/iblog[root@mysql u01]# mkdir -p /u01/my3306/log/binlog[root@mysql u01]# mkdir -p /u01/my3306/run[root@mysql u01]# mkdir -p /u01/my3306/tmp[root@mysql u01]# chown -R mysql:mysql /u01/my3306[root@mysql u01]# chmod 755 /u01/my33068. 解压mysql
[root@mysql u01]# tar -xzvf mysql-5.6.36.tar.gz9. 配置yum源,安装cmakle及一些必备的包,要求2.6版本及以上
yum install -y cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl10. 编译并安装
cmake \-DCMAKE_INSTALL_PREFIX=/u01/my3306 \-DINSTALL_DATADIR=/u01/my3306/data \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ ---DWITH_SSL=yes \ --安全套接字-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DMYSQL_UNIX_ADDR=/u01/my3306/run/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DSYSCONFDIR=/etc \-DWITH_READLINE=on[root@mysql mysql-5.6.36]# cd mysql-5.6.36[root@mysql mysql-5.6.36]# cmake -DCMAKE_INSTALL_PREFIX=/u01/my3306 -DINSTALL_DATADIR=/u01/my3306/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=yes -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/u01/my3306/run/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DSYSCONFDIR=/etc -DWITH_READLINE=on[root@mysql mysql-5.6.36]# make[root@mysql mysql-5.6.36]# make install11. 配置mysql参数
[root@mysql my3306]# pwd/u01/my3306[root@mysql my3306]# cat my.cnf[client]port=3306socket=/u01/my3306/mysql.sock[mysql]pid_file=/u01/my3306/run/mysqld.pid[mysqld]autocommit=1general_log=offexplicit_defaults_for_timestamp=true# systembasedir=/u01/my3306datadir=/u01/my3306/datamax_allowed_packet=1gmax_connections=3000max_user_connections=2800open_files_limit=65535pid_file=/u01/my3306/run/mysqld.pidport=3306server_id=101skip_name_resolve=ONsocket=/u01/my3306/run/mysql.socktmpdir=/u01/my3306/tmp#binloglog_bin=/u01/my3306/log/binlog/binlogbinlog_cache_size=32768binlog_format=rowexpire_logs_days=7log_slave_updates=ONmax_binlog_cache_size=2147483648max_binlog_size=524288000sync_binlog=100#logginglog_error=/u01/my3306/log/error.logslow_query_log_file=/u01/my3306/log/slow.loglog_queries_not_using_indexes=0slow_query_log=1log_slave_updates=ONlog_slow_admin_statements=1long_query_time=1#relayrelay_log=/u01/my3306/log/relaylogrelay_log_index=/u01/my3306/log/relay.indexrelay_log_info_file=/u01/my3306/log/relay-log.info#slaveslave_load_tmpdir=/u01/my3306/tmpslave_skip_errors=OFF#innodbinnodb_data_home_dir=/u01/my3306/log/ibloginnodb_log_group_home_dir=/u01/my3306/log/ibloginnodb_adaptive_flushing=ONinnodb_adaptive_hash_index=ONinnodb_autoinc_lock_mode=1innodb_buffer_pool_instances=8#defaultinnodb_change_buffering=insertsinnodb_checksums=ONinnodb_buffer_pool_size= 128Minnodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextendinnodb_doublewrite=ONinnodb_file_format=Barracudainnodb_file_per_table=ONinnodb_flush_log_at_trx_commit=1innodb_flush_method=O_DIRECTinnodb_io_capacity=1000innodb_lock_wait_timeout=10innodb_log_buffer_size=67108864innodb_log_file_size=1048576000innodb_log_files_in_group=4innodb_max_dirty_pages_pct=60innodb_open_files=60000innodb_purge_threads=1innodb_read_io_threads=4innodb_stats_on_metadata=OFFinnodb_support_xa=ONinnodb_use_native_aio=OFFinnodb_write_io_threads=10[mysqld_safe][root@mysql my3306]# chown -R mysql:mysql /u01/my330612. 初始化mysql脚本
[root@mysql my3306]# ./scripts/mysql_install_db --defaults-file=/u01/my3306/my.cnf --datadir=/u01/my3306/data --user=mysql13. 启动mysql
[mysql@mysql bin]$ ./mysqld_safe --defaults-file=/u01/my3306/my.cnf --user=mysql &[1] 17237[mysql@mysql bin]$ 170612 06:37:02 mysqld_safe Logging to '/u01/my3306/log/error.log'.170612 06:37:02 mysqld_safe Starting mysqld daemon with databases from /u01/my3306/data[mysql@mysql bin]$ mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.36-log Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.10 sec)