#卸载原有的mysql
yum remove mysql*
ls /etc/my.cnf*
mv /etc/my.cnf* /tmp/
#安装依赖包
yum install make cmake gcc gcc-c++ bison-devel ncurses-devel autoconf automake -y
#添加用户
groupadd mysql
useradd -r -g mysql mysql
#useradd -M -s /sbin/nologin mysql
#创建目录
mkdir -p /usr/local/mysql
mkdir -p /home/mysql
mkdir -p /home/data
mkdir -p /home/mysql/logs
mkdir -p /home/mysql/temp
#添加环境变量
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >>/etc/profile
source /etc/profile
#安装mysql
tar xf mysql-5.6.25.tar.gz
cd mysql-5.6.25
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/home/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
make
make install
#修改目录属性
chown -Rf mysql:mysql /usr/local/mysql
chown -Rf mysql:mysql /home/data
#初始化mysql
chmod +x /root/mysql-5.6.25/scripts/mysql_install_db
/root/mysql-5.6.25/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/data --defaults-file=/usr/local/mysql/my.cnf
#移除无用my.cnf
mv /usr/local/mysql/my.cnf /usr/local/mysql/my.cnf.bak
mv /etc/my.cnf /tmp/
#导入my.cnf文件
cat >> /usr/local/mysql/my.cnf << EOF
[client]
default-character-set =utf8
[mysqld]
server-id=10
log-bin = mysql-bin
#binlog-ignore-db=mysql
basedir = /usr/local/mysql
datadir = /home/data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names = 1
log_bin_trust_function_creators=1
#复制函数相关、主从多要开启
character-set-server=utf8
max_connections=1000
#慢查询日志
long_query_time=2
slow-query-log=On
slow_query_log_file="mysql_slow_query.log"
#将所有没有使用带索引的查询语句全部写到慢查询日志中,设置关闭,需要时再调用 set global log_queries_not_using_indexes=On 打开
log_queries_not_using_indexes=Off
#内存占用优化
innodb_buffer_pool_size = 28G
innodb_buffer_pool_instances = 2
tmp_table_size=200M
max_heap_table_size=200M
EOF
#修改my.cnf属性
chown -Rf mysql:mysql /usr/local/mysql/my.cnf
#拷贝启动脚本、启动
mv /etc/init.d/mysql /tmp/
cp /root/mysql-5.6.25/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
/etc/init.d/mysql start
chkconfig mysql on
#mysqladmin -u root password ‘xxxxxxx‘
#设置账号密码:mysql客户端
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘xxxxxxx‘ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ IDENTIFIED BY ‘xxxxxxx‘ WITH GRANT OPTION;
GRANT replication slave ON *.* TO ‘slave‘@‘%‘ IDENTIFIED BY ‘[email protected]‘;
flush privileges;
#updata mysql.user set password="*9FB2126F7514B6AF42B20E9E4B8E839B72E31396" where user=‘root‘ and host=‘%‘;
#开放iptables端口
#vim /etc/sysconfig/iptables
#-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
#/etc/init.d/iptables start