大网数据广告活动
服务器运维问答

Install mysql client NOT server on Centos7

· 52CE 我爱测

I am trying to just install a mysql client on a centos 7 server. I have a remote mysql server I need to connect to, I do not want to install the mysql server. From Centos 7 it will default to mariadb which is fine [root@server ~]…

问题原文

原帖链接 · Mike Meidl · CC BY-SA 4.0

I am trying to just install a mysql client on a centos 7 server.

I have a remote mysql server I need to connect to, I do not want to install the mysql server.

From Centos 7 it will default to mariadb which is fine

[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!

When I try to run mysql I get

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

I cannot figure out how to start it

[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 ~]#

已采纳解答

原帖链接 · moo · CC BY-SA 4.0

Your mysql client is currently trying to connect to a server running on the local machine (which doesn't exist).

You need to specify, on the command line, the connection string (including user, hostname, port etc) for the server you are trying to connect to.

$ mysql --help provides a full list of CLI options. The ones you need to look at in particular are:

  • -D / --database

  • -h / --host

  • -u / --user

  • -P / --port

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。