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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)   1、先查看 /etc/rc.

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

 

1、先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.

2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock

3、试试:service mysqld start

4、如果是权限问题,则先改变权限 #chown -R mysql:mysql /var/lib/mysql

[root@localhost ~]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost ~]# mysql -uroot -p

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
原因是,/var/lib/mysql 的访问权限问题。

shell> chown -R mysql:mysql /var/lib/mysql

接着启动服务器

shell> /etc/init.d/mysql start

服务器正常启动后察看 /var/lib/mysql 自动生成mysql.sock文件。

但是我的问题仍然没有得到解决。

问题终于解决:
方法: 修改/etc/my.conf:
[mysqld] 
datadir=/usr/local/mysql/data 
socket=/var/lib/mysql/mysql.sock 

[mysql.server] 
user=mysql 
basedir=/usr/local/mysql 

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as: 

[client] 
socket=/var/lib/mysql/mysql.sock 

发现依旧如此,运行/etc/init.d/mysql start报错:Starting MySQLCouldn't find MySQL manager or server 
是mysqld服务没启,运行/usr/local/mysql/bin/mysqld_safe &

问题解决

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
6月前
|
关系型数据库 MySQL Linux
mysql登录报错Can't create a new thread
mysql登录报错Can't create a new thread
|
6月前
|
SQL Oracle 关系型数据库
【MySQL异常】1093 - You can‘t specify target table ‘daily_job‘ for update in FROM clause
【MySQL异常】1093 - You can‘t specify target table ‘daily_job‘ for update in FROM clause
73 0
|
4月前
|
关系型数据库 MySQL Linux
远程连接mySQL数据库服务器出现错误号码****:Can‘t connect to mySQL server on ‘192.168.***.***‘ (0)
远程连接mySQL数据库服务器出现错误号码****:Can‘t connect to mySQL server on ‘192.168.***.***‘ (0)
57 0
|
5月前
|
Oracle 关系型数据库 MySQL
MySQL语句执行报错You can‘t specify target table for update in FROM clause
MySQL语句执行报错You can‘t specify target table for update in FROM clause
50 0
|
5月前
|
关系型数据库 MySQL 数据库
cant connect to local MySQL server through socket /tmp/mysql.sock (2)
cant connect to local MySQL server through socket /tmp/mysql.sock (2)
101 0
cant connect to local MySQL server through socket /tmp/mysql.sock (2)
|
6月前
|
缓存 关系型数据库 MySQL
Mysql备份时报错:mysqldump: Got error: 1016: Can't open file: '**.fr..
Mysql备份时报错:mysqldump: Got error: 1016: Can't open file: '**.fr..
|
3天前
|
SQL 存储 关系型数据库
MySQL Cluster集群安装及使用
MySQL Cluster集群安装及使用
|
18天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
7天前
|
关系型数据库 MySQL 数据库
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
32 4
|
1天前
|
关系型数据库 MySQL 数据安全/隐私保护
安装mysql和远程连接
安装mysql和远程连接
8 0