记一次ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql stat
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql start
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql stop
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# ps -A|grep mysql
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql start
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# vi /etc/rc.d/init.d/mysqld status
2 files to edit
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# netstat -a |grep 3306
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# ps -A | grep -i mysql
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# netstat -a |grep 3306
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# service start mysql
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]#
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# systemctl mysql start
Unknown operation ‘mysql’.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# systemctl start mysql
Failed to start mysql.service: Unit not found.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql -u root -p -S /var/lib/mysql/mysql.sock
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql -u root -p -S /var/lib/mysql/mysql.sock
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql -u root -p -S /var/lib/mysql/mysql.sock
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# rpm -qa | grep mysql
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# rpm -q mysql
package mysql is not installed
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# rpm -q mariadb
package mariadb is not installed
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# yum search mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
============================================== N/S matched: mysql ===============================================
MySQL-python.x86_64 : An interface to MySQL
MySQL-zrm.noarch : MySQL backup manager
akonadi-mysql.x86_64 : Akonadi MySQL backend support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
collectd-mysql.x86_64 : MySQL plugin for collectd
dmlite-plugins-mysql.x86_64 : MySQL plugin for dmlite
dovecot-mysql.x86_64 : MySQL back end for dovecot
dpm-copy-server-mysql.x86_64 : DPM copy server with MySQL database back-end
dpm-name-server-mysql.x86_64 : DPM name server with MySQL database back-end
dpm-server-mysql.x86_64 : Disk Pool Manager (DPM) server with MySQL database back-end
dpm-srm-server-mysql.x86_64 : DPM SRM server with MySQL database back-end
dspam-mysql.x86_64 : MySQL storage driver for libdspam
exim-mysql.x86_64 : MySQL lookup support for Exim
freeradius-mysql.x86_64 : MySQL support for freeradius
fts-mysql.x86_64 : File Transfer Service V3 mysql plug-in
gnokii-smsd-mysql.x86_64 : MySQL support for Gnokii SMS daemon
holland-mysql.noarch : MySQL library functionality for Holland Plugins
holland-mysqldump.noarch : Logical mysqldump backup plugin for Holland
holland-mysqllvm.noarch : Holland LVM snapshot backup plugin for MySQL
lfc-server-mysql.x86_64 : LCG File Catalog (LFC) server with MySQL database back-end
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
libgda-mysql.x86_64 : Mysql provider for libgda
libnss-mysql.x86_64 : NSS library for MySQL
libodb-mysql.x86_64 : MySQL ODB runtime library from Code Synthesis
libodb-mysql-devel.x86_64 : Development files for libodb-mysql
lighttpd-mod_authn_mysql.x86_64 : Authentication module for lighttpd that uses a MySQL database
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd that uses a MySQL database
mysql++.x86_64 : C++ wrapper for the MySQL C API
mysql++-devel.x86_64 : MySQL++ developer files (headers, examples, etc.)
mysql++-manuals.x86_64 : MySQL++ user and reference manuals
mysql-connector-java.noarch : Official JDBC driver for MySQL
mysql-connector-odbc.x86_64 : ODBC driver for MySQL
mysql-connector-python.noarch : MySQL Connector for Python 2
mysql-mmm.noarch : Multi-Master Replication Manager for MySQL
mysql-proxy.x86_64 : A proxy for the MySQL Client/Server protocol
mysql-proxy-devel.x86_64 : Development files for mysql-proxy
mysql-utilities.noarch : MySQL Utilities
mysqlreport.noarch : A friendly report of important MySQL status values
mysqltuner.noarch : MySQL configuration assistant
nagios-plugins-mysql.x86_64 : Nagios Plugin - check_mysql
nextcloud-mysql.noarch : MySQL database support for NextCloud
nodejs-mysql.noarch : A node.js driver for mysql
opendbx-mysql.x86_64 : MySQL backend - provides mysql support in opendbx
opensips-mysql.x86_64 : MySQL storage support for the OpenSIPS
owncloud-mysql.noarch : MySQL database support for ownCloud
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
pdns-backend-mysql.x86_64 : MySQL backend for pdns
perdition-mysql.x86_64 : Library to allow perdition to access MySQL based pop maps
perl-Crypt-MySQL.x86_64 : Emulate MySQL PASSWORD() function
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
perl-DateTime-Format-MySQL.noarch : Parse and format MySQL dates and times
perl-Test-mysqld.noarch : Mysqld runner for tests
php-ZendFramework-Db-Adapter-Mysqli.noarch : Zend Framework database adapter for mysqli
php-ZendFramework-Db-Adapter-Pdo-Mysql.noarch : Zend Framework database adapter for MySQL PDO
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php-pear-MDB2-Driver-mysql.noarch : MySQL MDB2 driver
php-pear-MDB2-Driver-mysqli.noarch : MySQL Improved MDB2 driver
poco-mysql.x86_64 : The Data/MySQL POCO component
preludedb-mysql.x86_64 : Plugin to use prelude with a MySQL database
proftpd-mysql.x86_64 : Module to add MySQL support to the ProFTPD FTP server
python2-PyMySQL.noarch : Pure-Python MySQL client library
python34-PyMySQL.noarch : Pure-Python MySQL client library
python34-mysql.x86_64 : An interface to MySQL
python34-mysql-debug.x86_64 : An interface to MySQL, built for the CPython debug runtime
qt-mysql.i686 : MySQL driver for Qt’s SQL classes
qt-mysql.x86_64 : MySQL driver for Qt’s SQL classes
qt3-MySQL.i686 : MySQL drivers for Qt 3’s SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3’s SQL classes
qt5-qtbase-mysql.i686 : MySQL driver for Qt5’s SQL classes
qt5-qtbase-mysql.x86_64 : MySQL driver for Qt5’s SQL classes
redland-mysql.x86_64 : MySQL storage support for Redland
root-sql-mysql.x86_64 : MySQL client plugin for ROOT
rsyslog-mysql.x86_64 : MySQL support for rsyslog
soci-mysql.x86_64 : MySQL back-end for soci
soci-mysql-devel.x86_64 : MySQL back-end for soci
tcl-mysqltcl.x86_64 : MySQL interface for Tcl
voms-mysql-plugin.x86_64 : VOMS server plugin for MySQL
wt-dbo-mysql.x86_64 : MySQL back-end for the Wt::Dbo ORM library
zabbix20-proxy-mysql.x86_64 : Zabbix proxy compiled to use MySQL
zabbix20-server-mysql.x86_64 : Zabbix server compiled to use MySQL
zabbix20-web-mysql.noarch : Zabbix web frontend for MySQL
zabbix22-proxy-mysql.x86_64 : Zabbix proxy compiled to use MySQL
zabbix22-server-mysql.x86_64 : Zabbix server compiled to use MySQL
zabbix22-web-mysql.noarch : Zabbix web frontend for MySQL
calligra-kexi-driver-mysql.x86_64 : Mysqwl driver for kexi
dmlite-dpmhead.x86_64 : EMI DPM Head Node (MySQL)
dmlite-dpmhead-dome.x86_64 : DPM Head Node (MySQL)
innotop.noarch : A MySQL and InnoDB monitor program
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mylvmbackup.noarch : Utility for creating MySQL backups via LVM snapshots
mysql-mmm-agent.noarch : MMM Database Server Agent Daemon and Libraries
mysql-mmm-monitor.noarch : MMM Monitor Server Daemon and Libraries
mysql-mmm-tools.noarch : MMM Control Scripts and Libraries
mytop.noarch : A top clone for MySQL
percona-xtrabackup.x86_64 : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB
php-phpmyadmin-sql-parser.noarch : A validating SQL lexer and parser with a focus on MySQL dialect
php-udan11-sql-parser.noarch : A validating SQL lexer and parser with a focus on MySQL dialect
phpMyAdmin.noarch : Handle the administration of MySQL over the World Wide Web
zabbix22-dbfiles-mysql.noarch : Zabbix database schemas, images, data and patches

Name and summary matches only, use “search all” for everything.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# yum search mariadb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
============================================= N/S matched: mariadb ==============================================
MariaDB-aws-key-management.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-backup.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-cassandra-engine.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-client.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-common.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-compat.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-connect-engine.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-cracklib-password-check.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-devel.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-gssapi-server.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-oqgraph-engine.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-rocksdb-engine.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-server.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-shared.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-test.x86_64 : MariaDB: a very fast and robust SQL database server
MariaDB-tokudb-engine.x86_64 : MariaDB: a very fast and robust SQL database server
mariadb-bench.x86_64 : MariaDB benchmark scripts and data
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-embedded.i686 : MariaDB as an embeddable library
mariadb-embedded.x86_64 : MariaDB as an embeddable library
mariadb-embedded-devel.i686 : Development files for MariaDB as an embeddable library
mariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable library
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mariadb-server.x86_64 : The MariaDB server and related files
mariadb.x86_64 : A community developed branch of MySQL
mariadb-test.x86_64 : The test suite distributed with MariaD
percona-xtrabackup.x86_64 : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB

Name and summary matches only, use “search all” for everything.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# yum install mariadb-server.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package mariadb-server is obsoleted by MariaDB-server, trying to install MariaDB-server-10.2.14-1.el7.centos.x86_64 instead
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or “yum-complete-transaction –cleanup-only” and “yum history redo last”, first to finish them. If those don’t work you’ll have to try removing/installing packages by hand (maybe package-cleanup can help).
The program yum-complete-transaction is found in the yum-utils package.
–> Running transaction check
—> Package MariaDB-server.x86_64 0:10.2.14-1.el7.centos will be installed
–> Processing Dependency: galera for package: MariaDB-server-10.2.14-1.el7.centos.x86_64
–> Running transaction check
—> Package galera.x86_64 0:25.3.23-1.rhel7.el7.centos will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================

Package Arch Version Repository Size

Installing:
MariaDB-server x86_64 10.2.14-1.el7.centos mariadb 109 M
Installing for dependencies:
galera x86_64 25.3.23-1.rhel7.el7.centos mariadb 8.0 M

Transaction Summary

Install 1 Package (+1 Dependent package)

Total download size: 117 M
Installed size: 499 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): galera-25.3.23-1.rhel7.el7.centos.x86_64.rpm | 8.0 MB 00:00:01

(2/2): MariaDB-10.2.14-centos73-x86_64-server.rpm | 109 MB 00:00:10

Total 11 MB/s | 117 MB 00:00:10
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : galera-25.3.23-1.rhel7.el7.centos.x86_64 1/2
Installing : MariaDB-server-10.2.14-1.el7.centos.x86_64 2/2
Verifying : MariaDB-server-10.2.14-1.el7.centos.x86_64 1/2
Verifying : galera-25.3.23-1.rhel7.el7.centos.x86_64 2/2

Installed:
MariaDB-server.x86_64 0:10.2.14-1.el7.centos

Dependency Installed:
galera.x86_64 0:25.3.23-1.rhel7.el7.centos

Complete!
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# mariadb
-bash: mariadb: command not found
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
Failed to stop mysqld.service: Unit mysqld.service not loaded.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit not found.
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# service mariadb start
Redirecting to /bin/systemctl start mariadb.service
[root@iZwz9egg8kg3dhglpnddd2Z sbin]#
[root@iZwz9egg8kg3dhglpnddd2Z sbin]# netstat -a grep 3306
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:webcache 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost:mxi 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN
tcp 0 0 iZwz9egg8kg3dh:webcache 60.191.38.78:9831 ESTABLISHED
tcp 0 0 iZwz9egg8kg3dhglp:47276 106.11.68.13:http ESTABLISHED
tcp 0 52 iZwz9egg8kg3dhglpnd:ssh 61.190.213.226:4296 ESTABLISHED
tcp 0 0 iZwz9egg8kg3dhglpnd:ssh 61.190.213.:itwo-server ESTABLISHED
tcp6 0 0 [::]:mysql [::]:* LISTEN
tcp6 0 0 iZwz9egg8kg3dhglp:mysql 61.190.213.226:5037 ESTABLISHED
tcp6 0 0 iZwz9egg8kg3dhglp:mysql 61.190.213.226:5039 ESTABLISHED
udp 0 0 iZwz9egg8kg3dhglpnd:ntp 0.0.0.0:*
udp 0 0 localhost:ntp 0.0.0.0:*
udp 0 0 0.0.0.0:ntp 0.0.0.0:*
udp6 0 0 [::]:ntp [::]:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 14315 /tmp/Aegis-

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 是一个常见的MySQL连接错误。它表示MySQL客户端无法通过指定的socket文件连接到本地MySQL服务器。 这个错误通常有几种可能的原因和解决方法: 1. MySQL服务器未运行:首先,请确保MySQL服务器正在运行。您可以使用命令`systemctl status mysql`检查MySQL服务的状态。如果MySQL没有运行,请使用`systemctl start mysql`命令启动它。 2. MySQL连接配置错误:检查连接配置文件(通常是`/etc/my.cnf`或`/etc/mysql/my.cnf`)。确保配置文件中的socket路径与实际的socket文件路径匹配。如果路径不正确,可以手动编辑配置文件并将其更正。 3. socket文件不存在或权限问题:检查指定的socket文件`/var/lib/mysql/mysql.sock`是否存在,并且具有正确的权限。如果文件不存在,可以尝试重新创建它,并确保它所在的目录具有正确的权限。您可以使用以下命令进行验证: ``` ls -l /var/lib/mysql/mysql.sock ``` 4. MySQL服务器监听地址错误:MySQL服务器可能只监听特定的IP地址或主机名。请确保您连接MySQL服务器时使用的是正确的主机名或IP地址。您可以尝试使用`-h`选项指定正确的主机名,例如: ``` mysql -h localhost ``` 希望这些解决方法能够帮助您解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'错误。如果问题仍然存在,请提供更多详细信息以便我能够提供进一步的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值