echo -e "\033[31m============================注意===============================\033[0m" echo -e "\033[31m#安装包放在/data/soft/下\033[0m" echo -e "\033[31m#安装路径在/data/app/下\033[0m" echo -e "\033[31m====================卸载系统自带MySQL安装包====================\033[0m" REMOVE=`rpm -qa | grep -i mariadb-libs` yum remove $REMOVE -y mkdir -p /data/app mkdir -p /data/soft sleep 2 echo "安装mysql所需插件......" yum install libaio -y echo -e "\033[31m====================下载安装包====================\033[0m" cd /data/soft wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-el7-x86_64.tar.gz tar xf mysql-5.7.21-el7-x86_64.tar.gz mv mysql-5.7.21-el7-x86_64 mysql mv mysql /data/app/ useradd -M -s /sbin/nologin mysql id mysql mkdir /data/app/mysql/{data,log} chown -R mysql.mysql /data/app/mysql/ echo -e "\033[31m====================创建mysql软链接====================\033[0m" ln -s /data/app/mysql/ mysql #编辑my.cnf cat << EOF > /etc/my.cnf [client] port = 3306 socket = /tmp/mysql.sock [mysqld] server_id=10 port = 3306 user = mysql character-set-server = utf8mb4 default_storage_engine = innodb log_timestamps = SYSTEM socket = /tmp/mysql.sock basedir = /data/app/mysql datadir = /data/app/mysql/data/ pid-file = /data/app/mysql/data/mysql.pid max_connections = 1000 max_connect_errors = 1000 table_open_cache = 1024 max_allowed_packet = 128M open_files_limit = 65535 log-bin=mysql-bin #####====================================[innodb]============================== innodb_buffer_pool_size = 1024M innodb_file_per_table = 1 innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_purge_threads = 2 innodb_flush_log_at_trx_commit = 1 innodb_log_file_size = 512M innodb_log_files_in_group = 2 innodb_log_buffer_size = 16M innodb_max_dirty_pages_pct = 80 innodb_lock_wait_timeout = 30 innodb_data_file_path=ibdata1:1024M:autoextend #####====================================[log]============================== log_error = /data/app/mysql/log/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/app/mysql/log/mysql-slow.log sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES EOF echo -e "\033[31m====================注意初始化数据库====================\033[0m" /data/app/mysql/bin/mysqld --initialize --user=mysql --basedir=/data/app/mysql --datadir=/data/app/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp echo -e "\033[31m====================授权====================\033[0m" cp /data/app/mysql/support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql cp /data/app/mysql/bin/* /data/app/sbin/ cd /lib/systemd/system wget http://ftp.zxblinux.com:8082/hjgj/mysql.service systemctl daemon-reload echo -e "\033[31m====================启动服务器并查看端口====================\033[0m" /etc/init.d/mysql start netstat -lntup|grep mysql grep "password" /data/app/mysql/log/mysql-error.log