Centos7.6安装mysql5.7教程——腾讯云

  1. 使用Linux命令(wget)下载mysql安装包:
    官网下载链接:https://downloads.mysql.com/archives/community/
    选择社区版本下载: MySQL Community Server (Archived Versions)
    这里可以自行选择所需版本
    以5.7为例:(mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar)如下所示:
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-1.el7.x86_64.rpm-bundle.tar

等待下载完成并查看:
自行解压后如下所示

tar -xvf mysql-5.7.33-1.el7.x86_64.rpm-bundle.tar

在这里插入图片描述

  1. 安装mysql:
yum -y install mysql-community-server-5.7.33-1.el7.x86_64.rpm

提示缺少依赖:
在这里插入图片描述

  1. 如上的报错,由于centos 7默认是mariadb数据库,再去安装mysql之前要先下载mariadb
[root@VM-centos ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@VM-centos ~]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64
error: Failed dependencies:
	libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
	libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
//存在依赖关系,强制卸载
[root@VM-centos ~]#  rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@VM-centos ~]# yum -y install mysql-community-server-5.7.33-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-server-5.7.33-1.el7.x86_64.rpm: mysql-community-server-5.7.33-1.el7.x86_64
Marking mysql-community-server-5.7.33-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.33-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.33-1.el7 for package: mysql-community-server-5.7.33-1.el7.x86_64
Loading mirror speeds from cached hostfile
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.33-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: mysql-community-server-5.7.33-1.el7.x86_64 (/mysql-community-server-5.7.33-1.el7.x86_64)
           Requires: mysql-community-common(x86-64) = 5.7.33-1.el7
Error: Package: mysql-community-server-5.7.33-1.el7.x86_64 (/mysql-community-server-5.7.33-1.el7.x86_64)
           Requires: mysql-community-client(x86-64) >= 5.7.9
 You could try using --skip-broken to work around the problem
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)

  1. 可知缺少:

按照提示,安装如下依赖:

rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm

client依赖报错:

[root@VM-centos ~]# rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.33-1.el7.x86_64

  1. 根据以上提示,先安装libs:
[root@VM-centos ~]# rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.33-1.el7################################# [100%]

再继续安装:

[root@VM-centos ~]# rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.33-1.e################################# [100%]

最后(正常情况下可以直接完成):

yum -y install mysql-community-server-5.7.33-1.el7.x86_64.rpm

在这里插入图片描述

  1. 查看mysql服务并启动:
[root@VM-centos ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@VM-centos ~]# systemctl start mysqld.service

  1. 查看临时密码并登录修改:
[root@VM-centos ~]#  grep "password" /var/log/mysqld.log

在这里插入图片描述
下面是官方文档,对于该问题的解释:
https://dev.mysql.com/doc/refman/5.7/en/validate-password.html
上述报错的原因:其实与validate_password_policy的值有关。
validate_password_policy有以下取值:
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
解决方法:
修改validate_password_policy参数的值

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

更改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
  1. 使用新密码登录完成:
    在这里插入图片描述
  2. 总结:
    以上是在使用腾讯云服务器安装mysql时所涉及的一些问题。也是自己的学习过程,相比Window等常用的操作系统。Linux上不同的配置有时候就有不同的效果。当然也可以通过Docker进行安装。在安装完mysql之后,需要在服务器的防火墙中开启端口放行,才能进行远程访问。当然这里不建议使用默认的3306端口!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值