CentOS7搭建LNMP--安装MySQL5.7.34

本文详细介绍了如何在CentOS7上搭建LNMP环境,重点是安装MySQL5.7.34。首先从mysql官网下载安装包,接着创建目录并解压。由于CentOS7预装了mariadb,需要先删除以避免冲突。然后按照依赖顺序安装rpm包,并启动mysql服务。最后,配置mysql密码和安全策略,包括如何查看默认密码和设置不同复杂度级别的新密码。
摘要由CSDN通过智能技术生成

 1.下载mysql安装包

进入mysql官网的community进行下载:MySQL :: Download MySQL Community Server

现在最新的版本是mysql8.0,但是8.0是全新的架构,所以一般还是用的5.7版本的,这就需要我们选其他版本的mysql。按照如下步骤即可。

[root@ceshi ~]# cd /usr/local/src
[root@ceshi src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar

2.创建mysql-5.7.34目录,将下载的tar包解压到该目录下

[root@ceshi src]# mkdir mysql-5.7.34
[root@ceshi src]# ls
mysql-5.7.34  mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
[root@ceshi src]# tar -xvf mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar -C /usr/local/src/mysql-5.7.34

#进入目录查看安装情况
[root@ceshi src]# cd mysql-5.7.34
[root@ceshi mysql-5.7.34]# ls
mysql-community-client-5.7.34-1.el7.x86_64.rpm
mysql-community-common-5.7.34-1.el7.x86_64.rpm
mysql-community-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-embedded-5.7.34-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.34-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-libs-5.7.34-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm
mysql-community-server-5.7.34-1.el7.x86_64.rpm
mysql-community-test-5.7.34-1.el7.x86_64.rpm

注意:网上说centos7自带类mysql数据库mariadb,会跟mysql冲突,要先删除,我们就先删除它吧。

[root@ceshi mysql-5.7.34]# rpm -qa|grep mariadb

#卸载mariadb
[root@ceshi mysql-5.7.34]# rpm -e --nodeps mariadb-libs

3.接下来按以下顺序安装解压好的rpm包,因为它们有依赖关系(也可以将它们全部安装,因为后面安装其他服务的时候可能会用到,能正常用mysql这几个就够了)

[root@ceshi mysql-5.7.34]# rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm 
警告:mysql-community-common-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.34-1.e################################# [100%]

[root@ceshi mysql-5.7.34]# rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm 
警告:mysql-community-libs-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.34-1.el7################################# [100%]

[root@ceshi mysql-5.7.34]# rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm 
警告:mysql-community-client-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.34-1.e################################# [100%]

[root@ceshi mysql-5.7.34]# rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.34-1.e################################# [100%]

然后启动mysql服务

[root@ceshi src]# systemctl start mysqld

#查看服务状态
[root@ceshi src]# ss -naltp|grep mysqld
LISTEN     0      80          :::3306                    :::*                   users:(("mysqld",pid=2035,fd=21))

4.配置mysql密码及安全策略

mysql安装后会自动给root用户设置随机密码,重置密码和配置安全策略需要这个默认密码。使用命令grep "password" /var/log/mysqld.log或者cat /var/log/mysqld.log |grep password即可查看。root@localhost: 后面的就是默认密码。

[root@ceshi src]# cat /var/log/mysqld.log |grep password
2021-06-11T14:06:17.357353Z 1 [Note] A temporary password is generated for root@localhost: LqJkSFFtc6.i

新密码可以在网上找个密码生成器生成就行了。mysql密码复杂度分三种:

低:0       只要求长度,默认8位

中:1       要求长度、数字、大小写、特殊字符

高:2      要求长度、数字、大小写、特殊字符、字典文件

默认复杂度为1

[root@ceshi src]# mysql_secure_installation

Securing the MySQL server deployment.


#输入默认密码
Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

#输入新密码
New password: 

Re-enter new password: 

#接着就可以配置安全策略了

4.测试

[root@ceshi src]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值