当前位置: 首页 > 编程笔记 >

mysql服务启动却连接不上的解决方法

张鹏云
2023-03-14
本文向大家介绍mysql服务启动却连接不上的解决方法,包括了mysql服务启动却连接不上的解决方法的使用技巧和注意事项,需要的朋友参考一下

mysql服务启动,但是连接不上,如何解决?

登陆报错:

  root@localhost:~# mysql -u root -p
  Enter password:
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  root@localhost:~# service mysqld restart
  Shutting down MySQL..                   [ OK ]
  Starting MySQL.                      [ OK ]
  root@localhost:~# mysql -u root -p
  Enter password:
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

分析原因:

原因不详,知道了补上

解决方案一:

 root@localhost:~# find / -name mysql.sock
 /tmp/mysql.sock
 root@localhost:~# mysql -u root -p -S /tmp/mysql.sock
 Enter password:
 Welcome to the MySQL monitor. Commands end with ; or \g.
 Your MySQL connection id is 1
 Server version: 5.6.15-log Source distribution

 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

 Oracle is a registered trademark of Oracle Corporation and/or its
 affiliates. Other names may be trademarks of their respective
 owners.

 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 mysql>

解决方案二:

 root@localhost:~# find / -name mysql.sock
 /tmp/mysql.sock
 root@localhost:~# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

# 加上下面的这段代码即可
[mysql]
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

root@localhost:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.15-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。

 类似资料:
  • 本文向大家介绍Workbench连接不上阿里云服务器Ubuntu的Mysql解决方法(已测),包括了Workbench连接不上阿里云服务器Ubuntu的Mysql解决方法(已测)的使用技巧和注意事项,需要的朋友参考一下 这两天为了解决workbench连接不上阿里云服务器的问题,搞得头大,网上搜到的教程都大同小异,但唯独到我这就是行不通。不过好在最后终于解决了,记录一下这个坑爹的过程。 使用的环境

  • 本文向大家介绍解决“无法启动mysql服务 错误1069”的方法,包括了解决“无法启动mysql服务 错误1069”的方法的使用技巧和注意事项,需要的朋友参考一下 今天还在路上的时候,同事就发来消息,说网站后台无法访问了,那个急啊! 赶到公司,登陆服务器,正常,还好,看来不是服务器自身的问题,看错误提示,应该是mysql的问题了。 到服务选项里已查看,果然,未启动状态,启动MYSQL的时候提示错误

  • 本文向大家介绍MySQL 5.7.9 服务无法启动-“NET HELPMSG 3534”的解决方法,包括了MySQL 5.7.9 服务无法启动-“NET HELPMSG 3534”的解决方法的使用技巧和注意事项,需要的朋友参考一下 安装过程参考自:MySQL 5.6 for Windows 解压缩版配置安装 成功安装以后,启动MySQL,输入: 提示: ”MySQL 服务无法启动,服务没有报告任何

  • 本文向大家介绍Oracle监听器服务不能启动的解决方法,包括了Oracle监听器服务不能启动的解决方法的使用技巧和注意事项,需要的朋友参考一下 Oracle监听器服务不启动的时候可采取以下措施予以解决: 一、连接主机字符串,提示没有监听器 二、运行监听器,提示地址的协议专用组件指定不正确 在开始菜单运行中键入lsnrctl 连接至(DESCRIPTION=(ADDRESS=(PROTOCOL=TC

  • 本文向大家介绍SQL Agent服务无法启动的解决方法,包括了SQL Agent服务无法启动的解决方法的使用技巧和注意事项,需要的朋友参考一下 问题现象 从阿里云上镜像过来的一台数据库服务器,SQL Agent服务启动不了,提示服务启动后停止。(原数据库服务器是正常的,怀疑跟镜像有关) 如下是系统日志和SQL Agent的日志 2016-05-20 11:09:03 - ? [100] Micro

  • 本文向大家介绍MySQL启动错误解决方法,包括了MySQL启动错误解决方法的使用技巧和注意事项,需要的朋友参考一下 一般情况下mysql的启动错误还是很容易排查的,但是今天我们就来说一下不一般的情况。拿到一台服务器,安装完mysql后进行启动,启动错误如下: 有同学会说,哥们儿你是不是buffer pool设置太大了,设置了96G内存。这明显提示无法分配内存嘛。如果真是这样也就不在这里进行分享了,