/ 前言 /
目前MySQL最高版本为8.0, 但是使用较少, 本文主要分享MySQL5.7的安装流程, 并附有MySQL官网下载地址
/ 1 / 安装前准备
1 . 检查是否已安装MySQL
rpm -qa |grep -i mysql
如果有显示如下所示信息请先卸载MySQL
[root@localhost ~]# rpm -qa |grep -i mysql
mysql-community-libs-5.7.30-1.el7.x86_64
mysql-community-libs-compat-5.7.30-1.el7.x86_64
mysql57-community-release-el7-7.noarch
mysql-community-common-5.7.30-1.el7.x86_64
mysql-community-client-5.7.30-1.el7.x86_64
mysql-community-server-5.7.30-1.el7.x86_64
卸载命令
yum -y remove mysql-community-libs-5.7.30-1.el7.x86_64
yum -y remove mysql-community-libs-compat-5.7.30-1.el7.x86_64
yum -y remove mysql57-community-release-el7-7.noarch
...
2 . 下载MySQL安装包
MySQL官网下载地址
根据操作系统版本选择对应的rpm包
使用wget
命令下载安装包
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
/ 2 / 开始安装
1 . 添加MySQL Yum存储库
sudo yum localinstall mysql80-community-release-el7-3.noarch.rpm
2 . 选择发行系列(可跳过)
可以选择安装哪个版本的MySQL
yum repolist all | grep mysql
# 关闭5.7版本
sudo yum-config-manager --disable mysql57-community
# 打开5.6版本
sudo yum-config-manager --enable mysql56-community
3 . 安装MySQL
sudo yum -y install mysql-community-server
4 . 启动MySQL
# 启动MySQL服务
sudo service mysqld start
Starting mysqld:[ OK ]
# 查看MySQL状态
sudo service mysqld status
[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2020-05-17 08:50:34 EDT; 22min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 7104 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 7068 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 7111 (mysqld)
CGroup: /system.slice/mysqld.service
└─7111 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
/ 3 / 登录MySQl
1 . 查看默认root用户密码
sudo grep 'temporary password' /var/log/mysqld.log
[root@localhost ~]# sudo grep 'temporary password' /var/log/mysqld.log
1 [Note] A temporary password is generated for root@localhost: zyrBDGiuE6=i
2 . 登录
mysql -uroot -pzyrBDGiuE6=i
在登录时MySQL会显示一条警告
mysql: [Warning] Using a password on the command line interface can be insecure.
这个是MySQL希望为了安全起见, 在使用命令行登录时不要把密码明文展示在终端中, 不需要管
3. 修改默认密码
MySQL5.7有默认的密码策略
validate_password 默认情况下已安装。实施的默认密码策略validate_password要求密码至少包含一个大写字母,一个小写字母,一位数字和一个特殊字符,并且密码总长度至少为8个字符。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
不想按照这个策略创建密码可以修改MySQL的密码策略
# 修改策略为最低级别
set global validate_password_policy=0;
# 修改密码长度
set global validate_password_length=4;
参考文章
MySQL 5.7参考手册