CENTOS7二进制安装MYSQL.sh

#!/bin/bash
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
yum -y install cmake gcc gcc-c++ bison ncurses ncurses-devel wget
mkdir -p /data/mys &&cd /data/mys
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
tar xf mysql-5.7.22.tar.gz
rm -f mysql-5.7.22.tar.gz
cd /data/mys/mysql-5.7.22/
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz --no-check-certificate
tar xf boost_1_59_0.tar.gz
rm -f boost_1_59_0.tar.gz
mv boost_1_59_0 boost
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DWITH_BOOST=/data/mys/mysql-5.7.22/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
make && make install
cat >/etc/my.cnf<<EOF
[client]
default-character-set = utf8mb4
socket=/data/mysql/mysql.sock
[mysql]
default-character-set = utf8mb4
[mysqld]
port=3306
user=mysql
basedir=/data/mysql
datadir=/data/mysql/data
log-error=/data/mysql/logs/error.log
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysqld.pid
default-time-zone = '+8:00'
innodb_online_alter_log_max_size=128M
innodb_open_files=3000
table_open_cache=2000
innodb_lock_wait_timeout=120
innodb_log_files_in_group=3
thread_cache_size=100
max_connect_errors=200
myisam_sort_buffer_size=64M
back_log=800
server-id=1
innodb_log_file_size=1G
innodb_buffer_pool_size=1G
log_bin_trust_function_creators=1
character_set_server=utf8mb4
default_storage_engine=InnoDB
wait_timeout=28800
expire_logs_days=7
long_query_time=1
binlog_format=ROW
log-bin=mysql-bin
tmp_table_size=64M
read_buffer_size=4M
join_buffer_size=8M
sort_buffer_size=16M
max_heap_table_size=64M
binlog_cache_size=4M
max_allowed_packet=20M
max_connections=2000
long_query_time=1
slow-query-log=ON
log-output=TABLE
default_authentication_plugin = mysql_native_password
symbolic-links=0
lower_case_table_names=1
includedir /etc/my.cnf.d
EOF
mkdir -p /etc/my.cnf.d
mkdir -p /data/mysql/logs
touch /data/mysql/logs/error.log
chown -R mysql:mysql /data/mysql
/data/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/data/mysql \
--datadir=/data/mysql/data
#添加环境变量
cat >>/etc/profile<<EOF
PATH=$PATH:/data/mysql/bin:
EOF
source /etc/profile
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl daemon-reload && systemctl enable mysql && systemctl start mysql
mysqld_safe --defaults-file=/etc/my.cnf
#设置密码为123456并允许从任何地方登陆
mysql -uroot -e "SET PASSWORD = PASSWORD('123456');"
mysql -uroot -p123456 -e "use mysql;UPDATE user SET host = '%' WHERE user = 'root';"
mysql -uroot -p123456 -e "flush privileges;"
rm -fr /data/mys
rm -f $0

标签: none

评论已关闭