MySQL5.7.17安装

#!/bin/bash
soft_dir=/opt

#安装cmake 3.7.2
cd $soft_dir
yum -y install ncurses-devel
wget -c https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
tar zxf cmake-3.7.2.tar.gz && cd cmake-3.7.2
./configure –prefix=/usr/local/cmake && gmake && gmake install
ln -sfv /usr/local/cmake/bin/* /usr/bin/

#安装boost_1_59_0.tar.gz
cd $soft_dir
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
cd /usr/local
cp /opt/boost_1_59_0.tar.gz /usr/local/
tar zxf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh && ./b2 install

#安装mysql-5.7.17.tar.gz
cd $soft_dir
wget -c https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz
tar zxf mysql-5.7.17.tar.gz && cd mysql-5.7.17

#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=/tmp/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 -DWITH_EXTRA_CHARSETS=all -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost_1_59_0 &> /dev/null

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=/tmp/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 \
-DWITH_EXTRA_CHARSETS=all \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0

#remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

#find / -name CMakeCache.txt -exec rm -rf {} \; #全部删除后再重新cmake就OK了。该报错原因是未安装ncurses-devel yum -y install ncurses-devel

#出现:Build files have been written to: /opt/software/mysql-5.6.35执行如下命令:
make && make install

#创建程序用户
useradd -r -s /sbin/nologin mysql
echo $(id mysql)

#建立配置文件
cp -arp support-files/my-default.cnf /etc/my.cnf

#set my.cnf
mv /etc/my.cnf{,.back}
{
cat >> /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
port = 3306
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql
socket = /tmp/mysql.sock
pid-file = /data/mysql/localhost.localdomain.com.pid

#key_buffer = 16K
query_cache_limit = 256K
query_cache_size = 4M
max_allowed_packet = 1M
table_open_cache = 8
max_connections = 16

#thread_concurrency = 2
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K

default-storage-engine = MyISAM
default-tmp-storage-engine = MYISAM
loose-skip-innodb

loose-innodb-trx = 0
loose-innodb-locks = 0
loose-innodb-lock-waits = 0
loose-innodb-cmp = 0
loose-innodb-cmp-per-index = 0
loose-innodb-cmp-per-index-reset = 0
loose-innodb-cmp-reset = 0
loose-innodb-cmpmem = 0
loose-innodb-cmpmem-reset = 0
loose-innodb-buffer-page = 0
loose-innodb-buffer-page-lru = 0
loose-innodb-buffer-pool-stats = 0
loose-innodb-metrics = 0
loose-innodb-ft-default-stopword = 0
loose-innodb-ft-deleted = 0
loose-innodb-ft-being-deleted = 0
loose-innodb-ft-config = 0
loose-innodb-ft-index-cache = 0
loose-innodb-ft-index-table = 0
loose-innodb-sys-tables = 0
loose-innodb-sys-tablestats = 0
loose-innodb-sys-indexes = 0
loose-innodb-sys-columns = 0
loose-innodb-sys-fields = 0
loose-innodb-sys-foreign = 0
loose-innodb-sys-foreign-cols = 0

slow_query_log = 1 #是否启用慢查询 1:启用 0:禁用
long_query_time = 1 #设置超过指定时间即为慢查询语句,单位是秒,建议2秒内
slow_query_log_file = “/data/mysql/wanggaoli.com.slow.log” #设置慢查询日志存放位置

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[isamchk]

#key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
EOF
}

#初始化数据库
yum -y install autoconf &> /dev/null
mkdir -pv /data

#数据文件目录不应该有其他的文件,这个/data目录应该是一个空目录
/usr/local/mysql/bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql &> /dev/null

#设置环境变量
echo “PATH=$PATH:/opt/mysql/bin” >> /etc/profile
source /etc/profile
echo $PATH
chown -R mysql.mysql /data/mysql
chown -R mysql.mysql /usr/local/mysql

#添加系统服务

#/usr/bin/cp -arp support-files/mysql.server /etc/init.d/mysqld

#/usr/bin/chmod +x /etc/init.d/mysqld

#chkconfig mysqld on #开机自启
chmod +x /usr/local/mysql/support-files/mysql.server
echo “/usr/local/mysql/support-files/mysql.server start” >> /etc/rc.local
/usr/local/mysql/support-files/mysql.server start

#放行3306端口
echo “放行3306端口”
iptables -I INPUT -p tcp –dport 3306 -j ACCEPT
service iptables save
service iptables restart

#firewall-cmd –zone=public –add-port=3306/tcp –permanent

#systemctl stop firewalld

#systemctl start firewalld
 

-------------本文结束感谢您的阅读-------------