MySQL5.7二进制文件下载地址
链接:https://pan.baidu.com/s/1B5Vh-hQ4ksuvneCimFD2zA
提取码:9k7x
复制这段内容后打开百度网盘手机App,操作更方便哦
下载的文件请放在root目录下
按照以下方法安装会有个问题,那就是使用mysqldump等命令时,可能会提示socket文件找不到,需要添加参数--socket=/data/mysql/run/mysql.sock,或者把my.cnf里的socket对应目录路径改为/tmp/mysql.sock
以下内容为一键安装脚本。脚本仅适用于测试环境,生产环境请谨慎适用!
1#!/bin/bash 2#yum install openssl openssl-devel libaio* -y > /dev/null 3rpm -qa |grep mysql 4groupadd mysql 5useradd -g mysql mysql 6echo "unpacking,please wait! This will take about two minitues." 7tar -xf mysql-5.7.29-el7-x86_64.tar.gz 8echo "unpacking finish.doing next..." 9#rm -rf *.tar.gz 10mv mysql-5.7.29-el7-x86_64 mysql 11mkdir /data 12mv mysql /data/mysql 13rm -rf /usr/local/mysql 14ln -svf /data/mysql /usr/local/ 15cd /usr/local/mysql 16mkdir -pv /data/mysql/data 17mkdir -pv /data/mysql/log/iblog 18mkdir -pv /data/mysql/log/binlog 19mkdir -pv /data/mysql/log/relaylog 20mkdir -pv /data/mysql/run 21mkdir -pv /data/mysql/tmp 22chown -R mysql:mysql /data/mysql 23chmod -R 755 /data/mysql 24cat > /etc/my.cnf <<EOF 25# For advice on how to change settings please see 26# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html 27# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the 28# *** default location during install, and will be replaced if you 29# *** upgrade to a newer version of MySQL. 30#[mysqld] 31# Remove leading # and set to the amount of RAM for the most important data 32# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 33# innodb_buffer_pool_size = 128M 34# Remove leading # to turn on a very important data integrity option: logging 35# changes to the binary log between backups. 36# log_bin 37# These are commonly set, remove the # and set as required. 38# basedir = ..... 39# datadir = ..... 40# port = ..... 41# server_id = ..... 42# socket = ..... 43# Remove leading # to set options mainly useful for reporting servers. 44# The server defaults are faster for transactions and fast SELECTs. 45# Adjust sizes as needed, experiment to find the optimal values. 46# join_buffer_size = 128M 47# sort_buffer_size = 2M 48# read_rnd_buffer_size = 2M 49[mysql] 50# CLIENT # 51port = 3306 52socket = /data/mysql/run/mysql.sock 53disable-auto-rehash 54default-character-set=gbk 55[mysqld] 56# GENERAL # 57server_id = 128 58port = 3306 59user = mysql 60explicit_defaults_for_timestamp=true 61default-storage-engine = InnoDB 62character_set_server = gbk 63auto_increment_increment = 2 64auto_increment_offset = 1 65lower_case_table_names = 1 66socket = /data/mysql/run/mysql.sock 67pid_file = /data/mysql/run/mysqld.pid 68# MyISAM # 69key-buffer-size = 32M 70myisam-recover-options = FORCE,BACKUP 71# SAFETY # 72max_allowed_packet = 134217728 73max_connections = 8192 74max_user_connections = 8000 75open_files_limit = 65535 76skip-name-resolve 77sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 78sysdate-is-now = 1 79# DATA STORAGE # 80basedir = /data/mysql 81datadir = /data/mysql/data/ 82tmpdir = /data/mysql/tmp 83# BINARY LOGGING # 84log-bin = /data/mysql/log/binlog/master-bin 85log-bin-index = /data/mysql/log/binlog/master-bin.index 86expire-logs-days = 15 87sync-binlog = 1 88binlog_format = ROW 89#RELAY LOGGING 90relay-log=/data/mysql/log/relaylog/master-relay-bin 91relay-log-index=/data/mysql/log/relaylog/master-relay-bin.index 92sync_relay_log=1 93# CACHES AND LIMITS # 94tmp-table-size = 32M 95max-heap-table-size = 32M 96query-cache-type = 0 97query-cache-size = 0 98max-connections = 500 99thread-cache-size = 50 100open-files-limit = 65535 101table-definition-cache = 1024 102table-open-cache = 2048 103# INNODB # 104innodb_log_group_home_dir = /data/mysql/log/iblog 105innodb_data_home_dir = /data/mysql/log/iblog 106innodb-flush-method = O_DIRECT 107innodb-log-files-in-group = 2 108innodb-log-file-size = 256M 109innodb-flush-log-at-trx-commit = 1 110innodb-file-per-table = 1 111innodb-buffer-pool-size = 6G 112# LOGGING # 113general_log = off 114log-error = /data/mysql/log/mysql-error.log 115log-queries-not-using-indexes = 1 116slow-query-log = 1 117slow-query-log-file = /data/mysql/log/mysql-slow.log 118log_slave_updates=ON 119EOF 120 121cd /data/mysql/bin 122./mysqld --defaults-extra-file=/etc/my.cnf --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql --initialize-insecure 123./mysql_ssl_rsa_setup --basedir=/data/mysql --datadir=/data/mysql/data 124echo "PATH=/data/mysql/bin:$PATH" >/etc/profile.d/mysql.sh 125if [ -f /data/mysql/support-files/mysql.server ]; then 126cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld 127else 128echo "this is no mysql.server" 129fi 130sed -i 's/^mysqld_pid_file_path=.*$/mysqld_pid_file_path=\/data\/mysql\/run\/mysqld.pid/g' /etc/init.d/mysqld 131source /etc/profile.d/mysql.sh 132chkconfig --add mysqld 133systemctl stop firewalld 134systemctl disable firewalld 135setenforce 0 136sed -i 's/=enforcing/=disabled/g' /etc/selinux/config 137echo "mysql install finish" 138echo "please run 'source /etc/profile.d/mysql.sh'" 139echo "please run 'systemctl start mysqld'"
请在MySQL安装完成后,可根据自己的具体需求逐条在命令行中运行以下命令
1mysql -e "DELETE FROM mysql.user WHERE User='';" 2mysql -e "DELETE FROM mysql.user WHERE host='localhost';" 3mysql -e "DELETE FROM mysql.user WHERE host='localhost.localdomain';" 4mysql -e "DELETE FROM mysql.user WHERE host='::1';" 5mysql -e "SELECT host, user, authentication_string FROM mysql.user WHERE user = 'root';" 6mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;" 7mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '123456' WITH GRANT OPTION;" 8mysql -e "FLUSH PRIVILEGES;"
PS:
如果安装失败,或者想卸载
只需要删除/data/mysql和/usr/local/mysql就可以卸载干净了