MySQL客户端安装

MySQL客户端安装

背景:服务器容器中部署了MySQL数据库或者使用阿里云的RDS数据库,由于本地服务器没有安装客户端无法连接数据库做备份/还原,本文只是安装MySQL的客户端,不包括数据库。

下载rpm包

https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.25-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.25-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.25-1.el7.x86_64.rpm

也可自行去MySQL官网下载:官网地址
MySQL官网有很多不同的版本,我选择的是**MySQL Community Server **(社区服务器版本)
选择的MySQL是5.7版本,当前最新版本是8.0
以下为下载说明
MySQL客户端安装_第1张图片
MySQL客户端安装_第2张图片

安装rpm包

三者的版本必须一致,不能一个5.7,其他的8.0。
三者直接是有依赖顺序的,必须按顺序安装,如遇报错,请参考下面的

[root@d69 test]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
[root@d69 test]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm  
[root@d69 test]# rpm -ivh  mysql-community-client-5.7.25-1.el7.x86_64.rpm

测试MySQL客户端是否安装

[root@d69 test]# mysql --help
mysql  Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using  EditLine wrapper
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.

Usage: mysql [OPTIONS] [database]
以下内容省略

踩坑之旅

rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm 安装时报错

以下为报错信息

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

原因和解决:
如上的报错,由于centos 7默认是mariadb数据库,再去安装mysql之前要先下载mariadb

[root@d69 test]#  rpm -qa | grep mariadb
mariadb-devel-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@d69 test]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64
error: Failed dependencies:
        libmysqlclient.so.18()(64bit) is needed by (installed) mariadb-devel-1:5.5.60-1.el7_5.x86_64
        libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
        libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
        mariadb-libs(x86-64) = 1:5.5.60-1.el7_5 is needed by (installed) mariadb-devel-1:5.5.60-1.el7_5.x86_64
# 由于存在依赖关系,强制卸载
[root@d69 test]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

参考链接:

rpm包安装参考:MYSQL三种安装方式–rpm包安装
依赖报错问题解决:安装mysql数据库及问题解决方法

你可能感兴趣的:(mysql)