使用yum源的方式单机部署MySQL8.0.13
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
基本上开源的软件都支持三种安装方式,即rmp方式安装,源码安装和二进制方式安装。在实际生成环境中用到最多的方式莫过于二进制方式安装或者rmp方式安装。其中rmp方式安装是最常见的,比如Linux的Redhat/CentOS法相版本的yum管理工具,其实就是基于rpm方式安装,只不过它能帮我们解决rpm包的依赖关系即可。我在之前的笔记中介绍过MySQL5.7版本的以上三种安装方式。最近在学习MySQL8.0的一些心特性,顺手整理一下学习笔记,本片博客我们一起来学习一下MySQL8.0版本的yum安装方式。
我个人并不喜欢yum方式安装,虽然它的安装方式比较简单 ,官方说需要配置yum源即可。但是yum方式安装的可移植性相当差,官方参考地址:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html。
一.安装MySQL前准备工作
1>.操作环境
[root@node101 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@node101 ~]#
[root@node101 ~]# uname -r
3.10.0-327.el7.x86_64
[root@node101 ~]#
[root@node101 ~]# uname -m
x86_64
[root@node101 ~]#
[root@node101 ~]# hostname
node101.yinzhengjie.org.cn
[root@node101 ~]#
[root@node101 ~]# hostname -i
172.30.1.101
[root@node101 ~]#
[root@node101 ~]# free -h
total used free shared buff/cache available
Mem: 3.5G 124M 3.1G 8.4M 232M 3.2G
Swap: 2.0G 0B 2.0G
[root@node101 ~]#
[root@node101 ~]#
2>.卸载与mysql相关的服务
[root@node101 ~]# ls /etc/my.cnf #我们查看mysql的默认配置文件存放路径,发现我们还没有安装就已经又它存在啦!
/etc/my.cnf
[root@node101 ~]#
[root@node101 ~]# rpm -qa | grep mysql #果不其然, 我们发现的确安装了mysql相关的安装包
pcp-pmda-mysql-3.10.6-2.el7.x86_64
[root@node101 ~]#
[root@node101 ~]# rpm -qa | grep mariadb #原来我们在安装CentOs操作系统时,我的虚拟化软件默认的安装方式就帮我安装了mariadb呀!
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@node101 ~]#
[root@node101 ~]# yum -y remove pcp-pmda-mysql-3.10.6-2.el7.x86_64
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package pcp-pmda-mysql.x86_64 0:3.10.6-2.el7 will be erased
--> Processing Dependency: pcp-pmda-mysql for package: pcp-compat-3.10.6-2.el7.x86_64
--> Running transaction check
---> Package pcp-compat.x86_64 0:3.10.6-2.el7 will be erased
--> Processing Dependency: pcp-compat for package: pcp-3.10.6-2.el7.x86_64
--> Running transaction check
---> Package pcp.x86_64 0:3.10.6-2.el7 will be erased
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: pcp-pmda-summary-3.10.6-2.el7.x86_64
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: pcp-pmda-sendmail-3.10.6-2.el7.x86_64
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: pcp-pmda-weblog-3.10.6-2.el7.x86_64
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: pcp-pmda-lustrecomm-3.10.6-2.el7.x86_64
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: pcp-pmda-rpm-3.10.6-2.el7.x86_64
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: python-pcp-3.10.6-2.el7.x86_64
--> Processing Dependency: pcp = 3.10.6-2.el7 for package: pcp-pmda-roomtemp-3.10.6-2.el7.x86_64
--> Running transaction check
---> Package pcp-pmda-lustrecomm.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-roomtemp.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-rpm.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-sendmail.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-summary.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-weblog.x86_64 0:3.10.6-2.el7 will be erased
---> Package python-pcp.x86_64 0:3.10.6-2.el7 will be erased
--> Processing Dependency: python-pcp = 3.10.6-2.el7 for package: pcp-system-tools-3.10.6-2.el7.x86_64
--> Processing Dependency: python-pcp for package: pcp-pmda-gluster-3.10.6-2.el7.x86_64
--> Processing Dependency: python-pcp for package: pcp-pmda-json-3.10.6-2.el7.x86_64
--> Processing Dependency: python-pcp for package: pcp-pmda-zswap-3.10.6-2.el7.x86_64
--> Processing Dependency: python-pcp = 3.10.6-2.el7 for package: pcp-export-pcp2graphite-3.10.6-2.el7.x86_64
--> Processing Dependency: python-pcp for package: pcp-pmda-unbound-3.10.6-2.el7.x86_64
--> Running transaction check
---> Package pcp-export-pcp2graphite.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-gluster.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-json.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-unbound.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-pmda-zswap.x86_64 0:3.10.6-2.el7 will be erased
---> Package pcp-system-tools.x86_64 0:3.10.6-2.el7 will be erased
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00:00
epel/x86_64/metalink | 8.3 kB 00:00:00
epel/x86_64 | 4.7 kB 00:00:00
epel/x86_64/updateinfo | 949 kB 00:00:00
epel/x86_64/primary_db | 6.6 MB 00:00:07
extras/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 1.3 MB 00:00:01 Dependencies Resolved =================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Removing:
pcp-pmda-mysql x86_64 3.10.6-2.el7 @anaconda 95 k
Removing for dependencies:
pcp x86_64 3.10.6-2.el7 @anaconda 2.9 M
pcp-compat x86_64 3.10.6-2.el7 @anaconda 0.0
pcp-export-pcp2graphite x86_64 3.10.6-2.el7 @anaconda 12 k
pcp-pmda-gluster x86_64 3.10.6-2.el7 @anaconda 17 k
pcp-pmda-json x86_64 3.10.6-2.el7 @anaconda 66 k
pcp-pmda-lustrecomm x86_64 3.10.6-2.el7 @anaconda 26 k
pcp-pmda-roomtemp x86_64 3.10.6-2.el7 @anaconda 31 k
pcp-pmda-rpm x86_64 3.10.6-2.el7 @anaconda 45 k
pcp-pmda-sendmail x86_64 3.10.6-2.el7 @anaconda 39 k
pcp-pmda-summary x86_64 3.10.6-2.el7 @anaconda 34 k
pcp-pmda-unbound x86_64 3.10.6-2.el7 @anaconda 66 k
pcp-pmda-weblog x86_64 3.10.6-2.el7 @anaconda 159 k
pcp-pmda-zswap x86_64 3.10.6-2.el7 @anaconda 9.0 k
pcp-system-tools x86_64 3.10.6-2.el7 @anaconda 261 k
python-pcp x86_64 3.10.6-2.el7 @anaconda 400 k Transaction Summary
=================================================================================================================================
Remove 1 Package (+15 Dependent packages) Installed size: 4.1 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : pcp-pmda-roomtemp-3.10.6-2.el7.x86_64 1/16
Erasing : pcp-pmda-sendmail-3.10.6-2.el7.x86_64 2/16
Erasing : pcp-pmda-lustrecomm-3.10.6-2.el7.x86_64 3/16
Erasing : pcp-pmda-gluster-3.10.6-2.el7.x86_64 4/16
Erasing : pcp-pmda-zswap-3.10.6-2.el7.x86_64 5/16
Erasing : pcp-system-tools-3.10.6-2.el7.x86_64 6/16
Erasing : pcp-export-pcp2graphite-3.10.6-2.el7.x86_64 7/16
Erasing : pcp-pmda-json-3.10.6-2.el7.x86_64 8/16
Erasing : pcp-pmda-rpm-3.10.6-2.el7.x86_64 9/16
Erasing : pcp-pmda-summary-3.10.6-2.el7.x86_64 10/16
Erasing : pcp-pmda-weblog-3.10.6-2.el7.x86_64 11/16
Erasing : pcp-compat-3.10.6-2.el7.x86_64 12/16
Erasing : pcp-pmda-unbound-3.10.6-2.el7.x86_64 13/16
Erasing : pcp-3.10.6-2.el7.x86_64 14/16
Erasing : python-pcp-3.10.6-2.el7.x86_64 15/16
Erasing : pcp-pmda-mysql-3.10.6-2.el7.x86_64 16/16
Verifying : pcp-pmda-unbound-3.10.6-2.el7.x86_64 1/16
Verifying : pcp-pmda-lustrecomm-3.10.6-2.el7.x86_64 2/16
Verifying : pcp-pmda-sendmail-3.10.6-2.el7.x86_64 3/16
Verifying : python-pcp-3.10.6-2.el7.x86_64 4/16
Verifying : pcp-system-tools-3.10.6-2.el7.x86_64 5/16
Verifying : pcp-pmda-summary-3.10.6-2.el7.x86_64 6/16
Verifying : pcp-pmda-rpm-3.10.6-2.el7.x86_64 7/16
Verifying : pcp-pmda-roomtemp-3.10.6-2.el7.x86_64 8/16
Verifying : pcp-pmda-zswap-3.10.6-2.el7.x86_64 9/16
Verifying : pcp-3.10.6-2.el7.x86_64 10/16
Verifying : pcp-pmda-gluster-3.10.6-2.el7.x86_64 11/16
Verifying : pcp-compat-3.10.6-2.el7.x86_64 12/16
Verifying : pcp-export-pcp2graphite-3.10.6-2.el7.x86_64 13/16
Verifying : pcp-pmda-json-3.10.6-2.el7.x86_64 14/16
Verifying : pcp-pmda-weblog-3.10.6-2.el7.x86_64 15/16
Verifying : pcp-pmda-mysql-3.10.6-2.el7.x86_64 16/16 Removed:
pcp-pmda-mysql.x86_64 0:3.10.6-2.el7 Dependency Removed:
pcp.x86_64 0:3.10.6-2.el7 pcp-compat.x86_64 0:3.10.6-2.el7 pcp-export-pcp2graphite.x86_64 0:3.10.6-2.el7
pcp-pmda-gluster.x86_64 0:3.10.6-2.el7 pcp-pmda-json.x86_64 0:3.10.6-2.el7 pcp-pmda-lustrecomm.x86_64 0:3.10.6-2.el7
pcp-pmda-roomtemp.x86_64 0:3.10.6-2.el7 pcp-pmda-rpm.x86_64 0:3.10.6-2.el7 pcp-pmda-sendmail.x86_64 0:3.10.6-2.el7
pcp-pmda-summary.x86_64 0:3.10.6-2.el7 pcp-pmda-unbound.x86_64 0:3.10.6-2.el7 pcp-pmda-weblog.x86_64 0:3.10.6-2.el7
pcp-pmda-zswap.x86_64 0:3.10.6-2.el7 pcp-system-tools.x86_64 0:3.10.6-2.el7 python-pcp.x86_64 0:3.10.6-2.el7 Complete!
[root@node101 ~]#
卸载mysql相关的安装包([root@node101 ~]# yum -y remove pcp-pmda-mysql-3.10.6-2.el7.x86_64)
[root@node101 ~]# yum -y remove mariadb-libs-5.5.44-2.el7.centos.x86_64
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Processing Dependency: postfix = 2:2.10.1-6.el7 for package: 2:postfix-perl-scripts-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix-perl-scripts.x86_64 2:2.10.1-6.el7 will be erased
--> Processing Dependency: postfix-perl-scripts for package: pcp-pmda-postfix-3.10.6-2.el7.x86_64
--> Running transaction check
---> Package pcp-pmda-postfix.x86_64 0:3.10.6-2.el7 will be erased
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Removing:
mariadb-libs x86_64 1:5.5.44-2.el7.centos @anaconda 4.4 M
Removing for dependencies:
pcp-pmda-postfix x86_64 3.10.6-2.el7 @anaconda 8.6 k
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M
postfix-perl-scripts x86_64 2:2.10.1-6.el7 @anaconda 109 k Transaction Summary
=================================================================================================================================
Remove 1 Package (+3 Dependent packages) Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : pcp-pmda-postfix-3.10.6-2.el7.x86_64 1/4
Erasing : 2:postfix-perl-scripts-2.10.1-6.el7.x86_64 2/4
Erasing : 2:postfix-2.10.1-6.el7.x86_64 3/4
Erasing : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 4/4
Verifying : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 1/4
Verifying : pcp-pmda-postfix-3.10.6-2.el7.x86_64 2/4
Verifying : 2:postfix-perl-scripts-2.10.1-6.el7.x86_64 3/4
Verifying : 2:postfix-2.10.1-6.el7.x86_64 4/4 Removed:
mariadb-libs.x86_64 1:5.5.44-2.el7.centos Dependency Removed:
pcp-pmda-postfix.x86_64 0:3.10.6-2.el7 postfix.x86_64 2:2.10.1-6.el7 postfix-perl-scripts.x86_64 2:2.10.1-6.el7 Complete!
[root@node101 ~]#
卸载mariadb数据库([root@node101 ~]# yum -y remove mariadb-libs-5.5.44-2.el7.centos.x86_64)
[root@node101 ~]# rpm -qa | grep mysql #mysql相关的安装包被卸载了
[root@node101 ~]#
[root@node101 ~]# rpm -qa | grep mariadb #maridb相关的安装包被卸载了
[root@node101 ~]#
[root@node101 ~]# ls /etc/my.cnf #卸载成功后,配置文件也随之被删除啦!
ls: cannot access /etc/my.cnf: No such file or directory
[root@node101 ~]#
[root@node101 ~]#
3>.查看MySQl官网提供的yum资源(https://dev.mysql.com/downloads/repo/yum/)
4>.选择对应的操作系统
5>.无需登录,直接下载上传到服务器即可(或者咱们也可以直接在服务器上使用wget命令安装也是可以的哟!)
二.使用yum源的方式安装MySQL
1>.登录服务器,下载mysql的rpm源
[root@node101 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
--2019-01-17 11:40:56-- https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm [following]
--2019-01-17 11:40:57-- https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.51.209.162
Connecting to repo.mysql.com (repo.mysql.com)|23.51.209.162|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25820 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-1.noarch.rpm’ 100%[=======================================================================================>] 25,820 --.-K/s in 0.06s 2019-01-17 11:40:58 (434 KB/s) - ‘mysql80-community-release-el7-1.noarch.rpm’ saved [25820/25820] [root@node101 ~]#
[root@node101 ~]# ll
total 28
-rw-r--r--. 1 root root 25820 Apr 18 2018 mysql80-community-release-el7-1.noarch.rpm
[root@node101 ~]#
[root@node101 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2>.安装yum源
[root@node101 ~]# ll /etc/yum.repos.d/ | grep mysql
[root@node101 ~]#
[root@node101 ~]# ll
total 28
-rw-r--r--. 1 root root 25820 Apr 18 2018 mysql80-community-release-el7-1.noarch.rpm
[root@node101 ~]#
[root@node101 ~]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
warning: mysql80-community-release-el7-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-1 ################################# [100%]
[root@node101 ~]#
[root@node101 ~]# ll /etc/yum.repos.d/ | grep mysql
-rw-r--r--. 1 root root 1864 Feb 22 2018 mysql-community.repo
-rw-r--r--. 1 root root 1885 Feb 22 2018 mysql-community-source.repo
[root@node101 ~]#
[root@node101 ~]#
3>.安装MySQL服务
[root@node101 ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror, langpacks
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql80-community | 2.5 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 29 kB 00:00:00
(2/3): mysql-tools-community/x86_64/primary_db | 48 kB 00:00:00
(3/3): mysql80-community/x86_64/primary_db | 35 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.yun-idc.com
* extras: mirror.jdcloud.com
* updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.13-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.13-1.el7 for package: mysql-community-server-8.0.13-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.0 for package: mysql-community-server-8.0.13-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.13-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.0 for package: mysql-community-client-8.0.13-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.13-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:8.0.13-1.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Installing:
mysql-community-server x86_64 8.0.13-1.el7 mysql80-community 381 M
Installing for dependencies:
mysql-community-client x86_64 8.0.13-1.el7 mysql80-community 26 M
mysql-community-common x86_64 8.0.13-1.el7 mysql80-community 554 k
mysql-community-libs x86_64 8.0.13-1.el7 mysql80-community 2.3 M Transaction Summary
=================================================================================================================================
Install 1 Package (+3 Dependent packages) Total download size: 410 M
Installed size: 1.8 G
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.13-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-8.0.13-1.el7.x86_64.rpm is not installed
(1/4): mysql-community-common-8.0.13-1.el7.x86_64.rpm | 554 kB 00:00:02
(2/4): mysql-community-libs-8.0.13-1.el7.x86_64.rpm | 2.3 MB 00:00:13
(3/4): mysql-community-client-8.0.13-1.el7.x86_64.rpm | 26 MB 00:00:42
(4/4): mysql-community-server-8.0.13-1.el7.x86_64.rpm | 381 MB 00:25:40
---------------------------------------------------------------------------------------------------------------------------------
Total 269 kB/s | 410 MB 00:25:56
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql80-community-release-el7-1.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-8.0.13-1.el7.x86_64 1/4
Installing : mysql-community-libs-8.0.13-1.el7.x86_64 2/4
Installing : mysql-community-client-8.0.13-1.el7.x86_64 3/4
Installing : mysql-community-server-8.0.13-1.el7.x86_64 4/4
Verifying : mysql-community-server-8.0.13-1.el7.x86_64 1/4
Verifying : mysql-community-libs-8.0.13-1.el7.x86_64 2/4
Verifying : mysql-community-common-8.0.13-1.el7.x86_64 3/4
Verifying : mysql-community-client-8.0.13-1.el7.x86_64 4/4 Installed:
mysql-community-server.x86_64 0:8.0.13-1.el7 Dependency Installed:
mysql-community-client.x86_64 0:8.0.13-1.el7 mysql-community-common.x86_64 0:8.0.13-1.el7
mysql-community-libs.x86_64 0:8.0.13-1.el7 Complete!
[root@node101 ~]#
[root@node101 ~]# yum -y install mysql-community-server
4>.设置MySQL开机自启
[root@node101 ~]# systemctl enable mysqld #设置开机自启动
[root@node101 ~]#
[root@node101 ~]# systemctl start mysqld #启动MySQL
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# systemctl status mysqld #查看MySQL的运行状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2019-01-17 12:20:51 HKT; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 16701 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 16792 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─16792 /usr/sbin/mysqld Jan 17 12:20:44 node101.yinzhengjie.org.cn systemd[1]: Starting MySQL Server...
Jan 17 12:20:51 node101.yinzhengjie.org.cn systemd[1]: Started MySQL Server.
[root@node101 ~]#
[root@node101 ~]#
5>.查看mysql的启动日志([root@node101 ~]# tail /var/log/mysqld.log )
[root@node101 ~]# grep 'temporary password' /var/log/mysqld.log
2019-01-17T04:20:47.536393Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gZSt9j>Q;LZ. #这里mysql的临时密码!
[root@node101 ~]#
[root@node101 ~]#
6>.链接mysql服务器并修改密码
[root@node101 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.13 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; #这个报错很正常,说是你没有修改密不允许执行SQL语句
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql> alter user user() identified by 'yinzhengjie'; #这条命令是修改当前用户的密码没错,但是密码太简单,不符合默认的MEDIUM安全规则,用数字表示为1。
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>
mysql> alter user user() identified by 'yzj@2019MySQL'; #我们按照要求,修改符合MEDIUM安全策略的密码。
Query OK, 0 rows affected (0.06 sec) mysql> quit
Bye
[root@node101 ~]#
[root@node101 ~]# mysql -uroot -pyzj@2019MySQL
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like '%validate_password_policy%';
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| validate_password.policy | MEDIUM |
+--------------------------+--------+
1 row in set (0.00 sec) mysql>
使用修改后的密码链接mysql服务器
[root@node101 ~]# mysql -uroot -pyzj@2019MySQL #使用修改后的密码登录数据库
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like '%validate_password_policy%'; #查看MySQL默认设置的安全级别!我擦!原来是他在搞鬼,让我没法把密码设置短一些!
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| validate_password.policy | MEDIUM |
+--------------------------+--------+
1 row in set (0.00 sec) mysql>
mysql> set GLOBAL validate_password.policy=0; #我们把安全策略从1降低为0
Query OK, 0 rows affected (0.00 sec) mysql>
mysql> alter user user() identified by 'yinzhengjie'; #发现修改密码可以设置为简单的啦!
Query OK, 0 rows affected (0.11 sec) mysql> quit
Bye
[root@node101 ~]# mysql -uroot -pyinzhengjie #使用我自定义的密码登录
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like '%validate_password_policy%'; #在次查看mysql 的安全策略,其Value变为Low啦!
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| validate_password.policy | LOW |
+--------------------------+-------+
1 row in set (0.01 sec) mysql> quit
Bye
[root@node101 ~]#
validate_password_policy各项值说明:密码安全策略,默认MEDIUM策略(小伙们别着急,后期我会抓门写一篇关于它的笔记,等不及的小伙伴可以先看官网,使用谷歌右键翻译即可!)
策略 | 检查规则 |
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |