linux中mysql的安装流程
环境:
CentOS-7-x86_64-Minimal-1908.iso linux
MobaXterm_Installer_v12.4 远程连接工具
VMware-workstation-full-14.1.1.28517 虚拟机
需要安装的mysql
mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
软件安装连接 密码 epsw
**使用 **◎**标记的命令是在mysql安装过程中能够正确执行的命令**
一,先将mysql安装包上传到虚拟机中,会以进度条的形式显示上传文件的进度.(博主把mysql安装包上传在/root/software目录下)
二.对已经打包的mysql进行拆包
①首先我们来看一下上传的mysql的文件详情
[root@hdp01 software]# ll /root/software
总用量 785796
-rw-r--r--. 1 root root 195094741 5月 29 02:37 jdk-8u221-linux-x64.tar.gz
-rw-r--r--. 1 root root 609556480 5月 29 04:34 mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
②拆包,将mysql拆包后文件放在/usr/local目录下
[root@hdp01 software]# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar -C /usr/local
mysql-community-embedded-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-test-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm
三.我们需要安装的是mysql的服务端,因此我们先尝试使用rpm命令安装mysql-community-server-5.7.28-1.el7.x86_64.rpm
//进入/usr/local目录
cd /usr/local
//安装mysql-community-server-5.7.28-1.el7.x86_64.rpm
[root@hdp01 local]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
mysql-community-client(x86-64) >= 5.7.9 被 mysql-community-server-5.7.28-1.el7.x86_64 需要
mysql-community-common(x86-64) = 5.7.28-1.el7 被 mysql-community-server-5.7.28-1.el7.x86_64 需要
—> 这里发现还有server安装的依赖还没有安装,因此需要先安装依赖
先安装mysql-community-common-5.7.28-1.el7.x86_64.rpm吧,看到安装成功
◎[root@hdp01 local]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.28-1.e################################# [100%]
接下来安装mysql-community-client-5.7.28-1.el7.x86_64.rpm
[root@hdp01 local]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
错误:依赖检测失败:
mysql-community-libs(x86-64) >= 5.7.9 被 mysql-community-client-5.7.28-1.el7.x86_64 需要
----> 这里又缺少了依赖,提示我们先安装mysql-community-libs-5.7.28-1.el7.x86_64.rpm
[root@hdp01 local]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
错误:依赖检测失败:
mysql-community-common(x86-64) >= 5.7.9 被 mysql-community-libs-5.7.28-1.el7.x86_64 需要
mariadb-libs 被 mysql-community-libs-5.7.28-1.el7.x86_64 取代
----- > 这里提示mariadb-libs与 mysql-community-libs-5.7.28-1.el7.x86_64发生冲突
因此先卸载mariadb-libs
◎[root@hdp01 local]# rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps
现在可以安装mysql-community-libs-5.7.28-1.el7.x86_64.rpm了
◎[root@hdp01 local]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.28-1.el7################################# [100%]
接着安装mysql-community-client-5.7.28-1.el7.x86_64.rpm
◎[root@hdp01 local]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.28-1.e################################# [100%]
最后安装mysql-community-server-5.7.28-1.el7.x86_64.rpm
◎[root@hdp01 local]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.28-1.e################################# [100%]
◎[root@hdp01 local]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.28-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 这里的密钥不显示了: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.28-1.e################################# [100%]
---------> 到这里mysql的安装就结束了
四.查看mysql服务是否启动
[root@hdp01 local]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) <-----可以看到这里显示的是inactive(不活跃) 未开启
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
五,因此需要启动mysql服务项,并且查看mysql服务的状态
[root@hdp01 local]# systemctl start mysqld <---启动mysql服务项
[root@hdp01 local]# systemctl status mysqld <----查看mysql服务项的状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2020-05-29 05:15:22 CST; 8s ago <----running 确认mysql服务已启动
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 17169 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 17076 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 17171 (mysqld)
CGroup: /system.slice/mysqld.service
└─17171 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
5月 29 05:15:15 hdp01 systemd[1]: Starting MySQL Server...
5月 29 05:15:22 hdp01 systemd[1]: Started MySQL Server.
六,查询mysql的初始密码(密码保存在/var/log/mysqld.log文件中,此文件是服务项启动后生成的)
[root@hdp01 local]# cat /var/log/mysqld.log | grep password
2020-05-28T21:15:18.095437Z 1 [Note] A temporary password is generated for root@localhost: dyrNye9d8J=3
----> 可以看到 dyrNye9d8J=3 是此次安装mysql的初始密码
七,使用初始密码登录mysql
[root@hdp01 local]# mysql -uroot -pdyrNye9d8J=3
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 2
Server version: 5.7.28
Copyright (c) 2000, 2019, 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>
----> 已经成功登录进来了
八这下应该可以正常操作了吧,让我们来看看都有哪些数据吧
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
---->提示在这些操作之前,必须重置密码
九,重置密码
mysql> alter user root@localhost identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
----> 提示密码设置不符合密码策略
十,降低密码策略的安全级别(如果想设置复杂密码的可以跳过这一步,当然最后的远程授权密码也需要设置的复杂一些)
mysql> set global validate_password_policy=low;
Query OK, 0 rows affected (0.01 sec)
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
--->这个时候可以设置比较简单的6位长度的密码了
十一,重置密码(如果之前忽略了第十步,那么这个root用户密码和远程授权连接的密码都需要设置8位以上包含数字,字母大小写,特殊字符 )
mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
十二 :远程授权并设置远程连接的密码(这里的远程连接密码是111111)
如果想要远程连接mysql,需要进行远程授权操作(注意,一定要关闭防火墙,关闭防火墙要退出mysql)
mysql> grant all privileges on *.* to root@"%" identified by '111111' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit;
Bye
[root@hdp01 local]# systemctl stop firewalld //这个只是暂时关闭,永久关闭用systemctl disable firewalld
十二,使用navicate尝试连接虚拟机中的mysql
首先查看一下虚拟机的ip
ip addr ----> 得到主机ip
之后点击新建连接对话框的确定即可进入远程连接
十,查看密码策略
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 |
+--------------------------------------+--------+
对于mysql的密码策略
validate_password_policy | 具体的密码要求(组成) |
---|---|
LOW | 只检查密码长度 |
MEDIUM | 数字,字母大小写,特殊字符 ,这个是默认的密码策略 |
STRONG | 数字、小写/大写,特殊字符;字典文件 |