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

 更新时间:2017年03月30日 10:15:25   作者:CyanSkye  
这篇文章主要为大家详细介绍了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>

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

相关文章

  • 浅析MySQL并行复制

    浅析MySQL并行复制

    这篇文章主要介绍了MySQL并行复制的相关资料,帮助大家更好的理解和使用MySQL数据库,感兴趣的朋友可以了解下
    2020-11-11
  • mysql 常用命令集锦[绝对精华]

    mysql 常用命令集锦[绝对精华]

    测试环境:mysql 5.0.45 【注:可以在mysql中通过mysql> SELECT VERSION();来查看数据库版本】
    2009-06-06
  • MySQL 1303错误的解决方法(navicat)

    MySQL 1303错误的解决方法(navicat)

    今天在用navicat创建MYSQL存储过程的时候,总是出现错误,错误信息如下.
    2009-12-12
  • MySQL导入导出.sql文件及常用命令小结

    MySQL导入导出.sql文件及常用命令小结

    在MySQL Qurey Brower中直接导入*.sql脚本,是不能一次执行多条sql命令的,下面为大家介绍下MySQL导入导出.sql文件及常用命令
    2014-08-08
  • 最全的mysql查询语句整理

    最全的mysql查询语句整理

    这篇文章主要介绍了最全的mysql查询语句整理,需要的朋友可以参考下
    2016-06-06
  • MySQL中on duplicate key update的使用方法实例

    MySQL中on duplicate key update的使用方法实例

    在做数据统计的时候,我们经常会用到mysql的on duplicate key update语法来自动更新数据,下面这篇文章主要给大家介绍了关于MySQL中on duplicate key update的使用方法的相关资料,需要的朋友可以参考下
    2022-09-09
  • CentOS7安装MySQL8的超级详细教程(无坑!)

    CentOS7安装MySQL8的超级详细教程(无坑!)

    我们在Linux系统中,如果要使用关系型数据库的话,基本都是用的mysql,这篇文章主要给大家介绍了关于CentOS7安装MySQL8的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-06-06
  • mysql 5.7.11 安装配置教程

    mysql 5.7.11 安装配置教程

    这篇文章主要为大家详细介绍了mysql 5.7.11 安装配置教程,感兴趣的小伙伴们可以参考一下
    2016-06-06
  • 阿里云centos7中安装MySQL8.0.13的方法步骤

    阿里云centos7中安装MySQL8.0.13的方法步骤

    这篇文章主要介绍了阿里云centos7中安装MySQL8.0.13的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-07-07
  • Mysql错误:Too many connections的解决方法

    Mysql错误:Too many connections的解决方法

    这篇文章主要给大家介绍了关于Mysql错误Too many connections的解决方法,文中通过示例代码介绍的非常详细,对大家学习或者使用Mysql具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-06-06

最新评论