Mysql

在 Centos7 上安裝 mysql 客戶端而不是伺服器

  • April 2, 2020

我試圖在 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 ~]#

您的 mysql 客戶端目前正在嘗試連接到在本地電腦上執行的伺服器(該伺服器不存在)。

您需要在命令行上為您嘗試連接的伺服器指定連接字元串(包括使用者、主機名、埠等)。

$ mysql --help提供 CLI 選項的完整列表。您需要特別注意的是:

  • -D / --database
  • -h / --host
  • -u / --user
  • -P / --port

引用自:https://serverfault.com/questions/1010584