在 Centos7 上安装 mysql 客户端而不是服务器

在 Centos7 上安装 mysql 客户端而不是服务器

我正在尝试在 centos 7 服务器上安装 mysql 客户端。

我有一个需要连接的远程 mysql 服务器,我不想安装该 mysql 服务器。

从 Centos 7 开始,它将默认使用 mariadb,这样就可以了

[root@server ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
[root@server ~]# yum install mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.umd.edu
 * epel: mirror.math.princeton.edu
 * extras: mirror.atlanticmetro.net
 * updates: packages.oit.ncsu.edu
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.64-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.64-1.el7 for package: 1:mariadb-5.5.64-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.64-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                                     Arch                                                  Version                                                         Repository                                           Size
=============================================================================================================================================================================================================================================
Installing:
 mariadb                                                     x86_64                                                1:5.5.64-1.el7                                                  base                                                8.7 M
Installing for dependencies:
 mariadb-libs                                                x86_64                                                1:5.5.64-1.el7                                                  base                                                759 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 9.5 M
Installed size: 53 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): mariadb-libs-5.5.64-1.el7.x86_64.rpm                                                                                                                                                                           | 759 kB  00:00:00
(2/2): mariadb-5.5.64-1.el7.x86_64.rpm                                                                                                                                                                                | 8.7 MB  00:00:03
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                        2.4 MB/s | 9.5 MB  00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-libs-5.5.64-1.el7.x86_64                                                                                                                                                                                        1/2
  Installing : 1:mariadb-5.5.64-1.el7.x86_64                                                                                                                                                                                             2/2
  Verifying  : 1:mariadb-libs-5.5.64-1.el7.x86_64                                                                                                                                                                                        1/2
  Verifying  : 1:mariadb-5.5.64-1.el7.x86_64                                                                                                                                                                                             2/2

Installed:
  mariadb.x86_64 1:5.5.64-1.el7

Dependency Installed:
  mariadb-libs.x86_64 1:5.5.64-1.el7

Complete!

当我尝试运行 mysql 时,我得到了

[root@server ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

我不知道如何启动它

[root@server ~]# systemctl start mysql
Failed to start mysql.service: Unit not found.
[root@server ~]# systemctl start mysqld
Failed to start mysqld.service: Unit not found.
[root@server ~]# systemctl start mariadb
Failed to start mariadb.service: Unit not found.
[root@server ~]#

答案1

您的 mysql 客户端当前正在尝试连接到本地机器上运行的服务器(不存在)。

您需要在命令行上指定您尝试连接的服务器的连接字符串(包括用户、主机名、端口等)。

$ mysql --help提供了 CLI 选项的完整列表。您需要特别查看的是:

  • -D / --database

  • -h / --host

  • -u / --user

  • -P / --port

相关内容