系统版本:

  1. cat /etc/redhat-release
  2. CentOS Linux release 7.7.1908 (Core)
  1. 下载mysql官网yum源,下载地址https://dev.mysql.com/downloads/repo/yum/

    wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    
  2. 校验md5码
    image.png

    md5sum mysql80-community-release-el7-3.noarch.rpm 
    893b55d5d885df5c4d4cf7c4f2f6c153  mysql80-community-release-el7-3.noarch.rpm
    
  3. 安装yum源

    rpm -ivh mysql80-community-release-el7-3.noarch.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
    1:mysql80-community-release-el7-3  ################################# [100%]
    
  4. 查看yum源mysql版本

    yum repolist all | grep mysql
    mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
    mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
    mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
    mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
    mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community   disabled
    mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
    mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:    212
    mysql-connectors-community-source  MySQL Connectors Community -  disabled
    mysql-tools-community/x86_64       MySQL Tools Community         enabled:    132
    mysql-tools-community-source       MySQL Tools Community - Sourc disabled
    mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
    mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
    mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
    mysql55-community-source           MySQL 5.5 Community Server -  disabled
    mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
    mysql56-community-source           MySQL 5.6 Community Server -  disabled
    mysql57-community/x86_64           MySQL 5.7 Community Server    disabled
    mysql57-community-source           MySQL 5.7 Community Server -  disabled
    mysql80-community/x86_64           MySQL 8.0 Community Server    enabled:    283
    mysql80-community-source           MySQL 8.0 Community Server -  disabled
    
  5. 禁用8.0版本

    yum-config-manager --disable mysql80-community
    
  6. 启用5.7版本

    yum-config-manager --enable mysql57-community
    
yum repolist all | grep mysql                
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community   disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:    212
mysql-connectors-community-source  MySQL Connectors Community -  disabled
mysql-tools-community/x86_64       MySQL Tools Community         enabled:    132
mysql-tools-community-source       MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
mysql55-community-source           MySQL 5.5 Community Server -  disabled
mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
mysql56-community-source           MySQL 5.6 Community Server -  disabled
mysql57-community/x86_64           MySQL 5.7 Community Server    enabled:    524
mysql57-community-source           MySQL 5.7 Community Server -  disabled
mysql80-community/x86_64           MySQL 8.0 Community Server    disabled
mysql80-community-source           MySQL 8.0 Community Server -  disabled
  1. 安装mysql5.7,安装 MySQL 服务器包 ( mysql-community-server) 以及运行服务器所需组件的包,包括客户端包 ( mysql-community-client)、客户端和服务器的常见错误消息和字符集 ( mysql-community-common) 以及共享客户端库 ( mysql-community-libs) .

    yum install mysql-community-server -y
    
  2. 修改配置文件/etc/my.cnf ``` [client]

    user=root

    password=123.com

    socket=/data/mysql/mysql.sock port=3306

[mysqld] user=mysql server-id=1 port=3306 datadir=/data/mysql/db tmpdir=/data/mysql/tmp socket=/data/mysql/mysql.sock pid-file=/data/mysql/mysqld.pid log-error=/data/mysql/log/err.log max_connections=5000 wait_timeout=7200 interactive_timeout=7200 explicit_defaults_for_timestamp=1 lower_case_table_names=1 character_set_server=utf8mb4 collation_server=utf8mb4_bin transaction_isolation=READ-COMMITTED

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

tmp_table_size=67108864 max_heap_table_size=67108864 max_allowed_packet=32M open_files_limit=65535

slow-log

slow_query_log=on long_query_time=2 slow_query_log_file=/data/mysql/log/slow.log

binlog

binlog_format=ROW log-bin=/data/mysql/log/binlog/mysql-bin log-bin-index=/data/mysql/log/binlog/mysql-bin.index

innodb配置

innodb_buffer_pool_size=1G

innodb_additional_mem_pool_size=20M

innodb_log_buffer_size=16M innodb_flush_log_at_trx_commit=2 innodb_file_per_table=1 innodb_flush_method=O_DIRECT innodb_data_file_path=ibdata1:1024M:autoextend innodb_log_files_in_group=4 innodb_log_file_size=256M


9.  创建相关目录

mkdir -p /data/mysql mkdir -p /data/mysql/db mkdir -p /data/mysql/tmp mkdir -p /data/mysql/log mkdir -p /data/mysql/log/binlog chown -R mysql.mysql /data/mysql


10.  启动mysql

systemctl start mysqld systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2021-08-16 15:49:30 CST; 5s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 19684 ExecStart=/usr/sbin/mysqld —daemonize —pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 19632 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 19687 (mysqld) CGroup: /system.slice/mysqld.service └─19687 /usr/sbin/mysqld —daemonize —pid-file=/var/run/mysqld/mysqld.pid

Aug 16 15:49:09 wk2 systemd[1]: Starting MySQL Server… Aug 16 15:49:30 wk2 systemd[1]: Started MySQL Server.


11.  查看系统自动生成的默认密码

cat /data/mysql/log/err.log |grep password A temporary password is generated for root@localhost: Ltapq8TG%;9d


12.  修改密码策略,及修改默认密码

mysql -uroot -p

mysql> SHOW VARIABLES LIKE ‘validate_password%’; +———————————————————+————+ | Variable_name | Value | +———————————————————+————+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +———————————————————+————+ 7 rows in set (0.02 sec)

mysql> set global validate_password_policy=LOW; Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=6; Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘123.com’;

创建一个可以从

mysql> create user root@’%’ identified by ‘123.com’; Query OK, 0 rows affected (0.02 sec)

mysql> grant all on . to root@’%’; Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)



至此已完成安装!<br />目录结构

tree /data/mysql -L 2 /data/mysql ├── db │ ├── auto.cnf │ ├── ca-key.pem │ ├── ca.pem │ ├── client-cert.pem │ ├── client-key.pem │ ├── demo │ ├── ib_buffer_pool │ ├── ibdata1 │ ├── ib_logfile0 │ ├── ib_logfile1 │ ├── ib_logfile2 │ ├── ib_logfile3 │ ├── ibtmp1 │ ├── mysql │ ├── performance_schema │ ├── private_key.pem │ ├── public_key.pem │ ├── server-cert.pem │ ├── server-key.pem │ └── sys ├── log │ ├── binlog │ ├── err.log │ └── slow.log ├── mysql.sock ├── mysql.sock.lock └── tmp

8 directories, 20 files




离线安装5.7<br />相关mysql5.7的rpm包,放到其他centos7机器

find /var/cache/ -name “*.rpm” /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.35-1.el7.x86_64.rpm /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.35-1.el7.x86_64.rpm /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-libs-5.7.35-1.el7.x86_64.rpm /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-server-5.7.35-1.el7.x86_64.rpm

卸载centos自带的mariadb lib库
```shell
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

上传四个rpm包并安装mysql-server

rpm -ivh mysql-community-*

vim /etc/my.cnf

[client]
#user=root
#password=123.com
socket=/data/mysql/mysql.sock
port=3306

[mysqld]
user=mysql
server-id=1
port=3306
datadir=/data/mysql/db
tmpdir=/data/mysql/tmp
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysqld.pid
log-error=/data/mysql/log/err.log
max_connections=5000
wait_timeout=7200
interactive_timeout=7200
explicit_defaults_for_timestamp=1
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_bin
transaction_isolation=READ-COMMITTED
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
tmp_table_size=67108864
max_heap_table_size=67108864
max_allowed_packet=32M
open_files_limit=65535

#slow-log
slow_query_log=on
long_query_time=2
slow_query_log_file=/data/mysql/log/slow.log

#binlog
binlog_format=ROW
log-bin=/data/mysql/log/binlog/mysql-bin
log-bin-index=/data/mysql/log/binlog/mysql-bin.index

#innodb配置
innodb_buffer_pool_size=1G
#innodb_additional_mem_pool_size=20M
innodb_log_buffer_size=16M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
innodb_flush_method=O_DIRECT
innodb_data_file_path=ibdata1:1024M:autoextend
innodb_log_files_in_group=4
innodb_log_file_size=256M
mkdir -p /data/mysql
mkdir -p /data/mysql/db
mkdir -p /data/mysql/tmp
mkdir -p /data/mysql/log
mkdir -p /data/mysql/log/binlog
chown -R mysql.mysql /data/mysql
systemctl start mysqld
systemctl enable mysqld