脚本安装MySQL 8.0

wget -O mysql80.sh https://*.*.*.*/mysql80.sh

sh mysql80.sh

看到下面提示,输入[email protected]用户密码,保存好一会使用。另外root@localhost密码为空

please input [email protected] password, default bigops

>输入你的密码

mysql80.sh

#!/bin/sh

which "/usr/bin/systemctl" >/dev/null 2>&1
if [ $? == 0 ];then
    systemctl stop mysqld.service
else
    service mysqld stop
fi

if [ ! -z "$(ps aux|egrep mysqld|grep -v grep)" ];then 
   ps aux|egrep mysqld|grep -v grep|awk '{print $2}'|xargs kill -9
fi

if [ ! -d /opt/mysql-rpms ];then
   mkdir -p /opt/mysql-rpms
fi

inst(){
    wget -O /etc/my.cnf https://*.*.*.*/my-80.cnf
    chmod 644 /etc/my.cnf
    rm -rf /var/lib/mysql/*
    mysqld --user=mysql --lower-case-table-names=0 --initialize-insecure
    chown -R mysql:mysql /var/lib/mysql
    
    which "/usr/bin/systemctl" >/dev/null 2>&1
    if [ $? == 0 ];then
        systemctl start mysqld.service
    else
        service mysqld start
    fi

    echo
    echo ----------------------------------
    echo "press any key to continue"
    read

    echo ----------------------------------
    echo -e "please input [email protected] password, default bigops"
    echo -e ">\c"
    read mypass

    if  [ -z "${mypass}" ];then
        mypass='bigops'
    fi
    mysql -uroot -e "create user 'root'@'127.0.0.1' identified with mysql_native_password by '${mypass}'"
    mysql -uroot -e "grant all privileges on *.* to 'root'@'127.0.0.1'"
    if [ $? == 0 ];then
        echo
        echo ----------------------------------
        echo "Installed successfully, [email protected] password is ${mypass}"
        echo "please running command testing: mysql -uroot -h127.0.0.1 -p${mypass}"
        echo ----------------------------------
    else
        echo "Installed failure!"
    fi

}

osver=`rpm -qi centos-release|egrep Version|awk '{print $3}'`
cd /opt/mysql-rpms/
if [[ "${osver}" == 6 ]] && [[ `arch` == x86_64 ]];then
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-client-8.0.16-2.el6.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-common-8.0.16-2.el6.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-devel-8.0.16-2.el6.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-libs-8.0.16-2.el6.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-libs-compat-8.0.16-2.el6.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-server-8.0.16-2.el6.x86_64.rpm
    rpm -Uvh --force /opt/mysql-rpms/*-8.0*.el6.*.rpm   
    inst
elif [[ "${osver}" == 7 ]] && [[ `arch` == x86_64 ]];then
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-client-8.0.16-2.el7.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-common-8.0.16-2.el7.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-devel-8.0.16-2.el7.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-libs-8.0.16-2.el7.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm &
    wget -N -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-server-8.0.16-2.el7.x86_64.rpm
    rpm -Uvh --force /opt/mysql-rpms/*-8.0*.el7.*.rpm
    inst
else
    echo "current system is not supported"
fi

my-80.cnf

[client]
default-character-set=utf8mb4
port=3306
socket=/var/lib/mysql/mysql.sock

[mysql] 
default-character-set=utf8mb4

[mysqld]
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=3306

default_authentication_plugin=mysql_native_password
default_password_lifetime=0

lower_case_table_names=0

#skip-grant-tables

skip_ssl
explicit_defaults_for_timestamp=1

#open_files_limit=65535

back_log=1024
host_cache_size=0

skip-external-locking
skip-name-resolve

max_allowed_packet = 512M

table_open_cache = 1000
table_definition_cache = 1024
table_open_cache_instances = 64

sort_buffer_size = 4M
join_buffer_size = 4M

read_buffer_size = 128M
read_rnd_buffer_size = 128M

thread_cache_size = 768
thread_stack = 512K

tmp_table_size = 32M
max_heap_table_size = 32M

interactive_timeout=2147483
wait_timeout=2147483

max_connections=5000
max_connect_errors=100000

expire_logs_days=2

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

innodb_data_file_path=ibdata1:10M:autoextend
innodb_buffer_pool_size=2G
innodb_log_file_size=512M
innodb_log_buffer_size=8M
innodb_log_files_in_group=3
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_file_per_table=1
innodb_open_files=1000
innodb_lock_wait_timeout=300
innodb_thread_concurrency=0

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[safe_mysqld]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

你可能感兴趣的:(Linux)