安装
#清理历史环境
[root@linux-node1 ~]# yum remove mariadb-libs -y
#创建用户和组
[root@linux-node1 ~]# useradd mysql -s /sbin/nologin
#创建软件目录
[root@linux-node1 ~]# mkdir -p /app/database/
#创建数据目录
[root@linux-node1 ~]# mkdir -p /data/3306/
#创建日志目录
[root@linux-node1 ~]# mkdir -p /binlog/3306/
#授权
[root@linux-node1 ~]# chown -R mysql.mysql /app/ /data/ /binlog/
#下载二进制文件
[root@linux-node1 ~]# curl -O https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
7 725M 7 53.0M 0 0 1623k 0 0:07:37 0:00:33 0:07:04 0
#解压
[root@linux-node1 app]# tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
[root@linux-node1 ~]# mv mysql-5.7.28-linux-glibc2.12-x86_64.tar /app/
[root@linux-node1 ~]# cd /app/
[root@linux-node1 app]# mv mysql-5.7.28-linux-glibc2.12-x86_64 database/
[root@linux-node1 app]# cd database/
[root@linux-node1 database]# ll
total 0
drwxr-xr-x 9 root root 129 Jul 10 14:50 mysql-5.7.28-linux-glibc2.12-x86_64
#安装扩展库
[root@linux-node1 mysql]# yum install -y libaio-devel
#创建软连接
[root@linux-node1 database]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
[root@linux-node1 database]# ll
total 0
lrwxrwxrwx 1 root root 35 Jul 10 14:52 mysql -> mysql-5.7.28-linux-glibc2.12-x86_64
#设置环境
root@linux-node1 database]# vim /etc/profile
export PATH=/app/database/mysql/bin:$PATH
#生效配置
[root@linux-node1 database]# source /etc/profile
[root@linux-node1 database]# mysql -V
mysql Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using EditLine wrapper
初始化系统库表
#初始化数据,初始化管理员的临时密码
[root@WANGXIANG database]# mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
2020-07-10T16:18:14.213232Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-10T16:18:14.314098Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-10T16:18:14.332965Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-10T16:18:14.387882Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f4c2d64d-c2c8-11ea-b04c-000c297a2fa5.
2020-07-10T16:18:14.388532Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-10T16:18:14.701419Z 0 [Warning] CA certificate ca.pem is self signed.
2020-07-10T16:18:14.946135Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
新特性重要说明:
5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度: 字符混乱组合
3.密码过期时间180天
配置文件
[mysqld]
user=mysql
basedir=/app/database/mysql
datadir=/data/3306/
port=3306
socket=/tmp/mysql.sock
log_error=/data/3306/mysql.log
port=3306
server_id=6
log_bin=/binlog/3306/mysql-bin
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
使用systemd管理mysql
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/database/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@WANGXIANG support-files]# systemctl daemon-reload
[root@WANGXIANG support-files]# systemctl start mysqld
[root@WANGXIANG support-files]# systemctl status mysqld