#!/bin/bash
# How to install mysql8.0 on centos7 using generic binaries
# https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
# https://dev.mysql.com/doc/mysql-secure-deployment-guide/8.0/en/secure-deployment-post-install.html
#MySQL has a dependency on the libaio library
yum install libaio -y
#Obtain and Unpack the Distribution
mkdir -p /root/{jiankong_log,sh,software} && mkdir -p /data/3306
cd /root/software/
wget -c https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
# wget -c http://miyo.app/yunwei/mysql/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
cd /usr/local/
mv mysql-8* mysql
#Create a mysql User and Group
groupadd mysql
useradd -r -g mysql -c "MySQL Server" -d "/data/3306" -s /bin/false mysql
#Creating a Safe Directory For Import and Export Operations
cd /usr/local/mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
#Initializing the Data Directory
bin/mysqld --defaults-file=/etc/3306.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306
#Starting the Server using systemd
cd /usr/lib/systemd/system
cat > 3306.service << EOF
[Unit]
Description=MySQL Server(3306)
After=network.target,syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/3306.cnf
# Sets open_files_limit
LimitNOFILE=65530
LimitNPROC=65530
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
EOF
systemctl daemon-reload
systemctl start 3306
安装xtrabackup
rpm -ivh percona-xtrabackup-80-8.0.4-1.el7.x86_64.rpm
日志切割
备份脚本
password from /data/3306/error.log
echo 'alter user 'root'@'localhost' identified by 'aaa111222';'
echo 'CREATE USER 'root'@'%' IDENTIFIED BY 'aaa111222';'
echo 'grant all privileges on *.* to root@'%' WITH GRANT OPTION;'
配置文件参考
# The MySQL server
# by glq
[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
log_timestamps=system
default_authentication_plugin=mysql_native_password
explicit_defaults_for_timestamp
port = 3306
mysqlx_port = 33060
user = mysql
datadir = /data/3306
basedir = /usr/local/mysql
socket = /data/3306/mysql.sock
mysqlx_socket = /data/3306/mysqlx.sock
max_connect_errors = 99999999
slow_query_log = 1
long_query_time = 0.5
slow_query_log_file = /data/3306/slow.log
init-connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server = utf8mb4_general_ci
skip-character-set-client-handshake
bind-address=0.0.0.0
skip-external-locking
log-slave-updates
skip-name-resolve
skip-slave-start
server-id = 3306
log-bin = mysql-bin
relay-log = mysql-relay-bin
log-error=error.log
#------------- innodb --------------
default-storage-engine = InnoDB
innodb_buffer_pool_size = 256M
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
innodb_flush_method = O_DIRECT
[client]
user = mysql
port = 3306
socket = /data/3306/mysql.sock
[myisamchk]
key_buffer = 400M
sort_buffer_size = 400M
read_buffer = 256M
write_buffer = 256M
[mysqldump]
quick
quote-names
max_allowed_packet = 128M