在使用

deamon@deamon-H55M-S2:/usr/bin$ mysqladmin -u root -p shutdown

关闭MySQL之后试图通过:

deamon@deamon-H55M-S2:/usr/bin$ mysqld_safe &

来重启服务器,发现重启失败,显示权限不够:

/usr/bin/mysqld_safe: 548: /usr/bin/mysqld_safe: cannot create /var/lib/mysql/mysqld_safe.pid: Permission denied

于是加上sudo:

deamon@deamon-H55M-S2:~$ sudo mysqld_safe&
[4] 7998 [4]+ Stopped sudo mysqld_safe
deamon@deamon-H55M-S2:~$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

然后就出现了如题所示的错误。

解决方法是将用户切换成root,再重新启动。

deamon@deamon-H55M-S2:~$ su -
Password:
root@deamon-H55M-S2:~# mysqld_safe &
[1] 8155
root@deamon-H55M-S2:~# 2016-11-29T11:50:50.182755Z mysqld_safe Logging to syslog.
2016-11-29T11:50:50.186438Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2016-11-29T11:50:50.209538Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql root@deamon-H55M-S2:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2016, 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用户,mysql还可正常使用。至此该问题解决。

解决:error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'的更多相关文章

  1. error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

    http://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket- ...

  2. 【error】: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

    错误描述如下: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ...

  3. mysql之ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'解决方法

    LAMPP安装完成之后,mysql -u root -p连不上,报这个错误: ERROR 2002 (HY000): Can't connect to local MySQL server throu ...

  4. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'解决

    用XAMPP装装好mysql之后,mysql -uroot 连不上,报这个错误:   ERROR 2002 (HY000): Can't connect to local MySQL server t ...

  5. Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'解决

    安装上mysql后,报 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock',试了网上的方法 ...

  6. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)-mysql.sock丢失解决方案

    我们的LAMP是搭建在UBUNTU 12.04 LTS上的. LAMP是通过编译的方式进来安装的. 在一次处理意外挂机时由于未知的原因在重启后发现无法连接数据库了, 在打开网站时出现如下的的提示: E ...

  7. Running MYSQL 5.7 By Bash On Ubuntu On Windows:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    root@PC-RENGUOQIANG:/usr/sbin# /etc/init.d/mysql start * Starting MySQL database server mysqld [ OK ...

  8. ubuntu 下安装 mysql 启动报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    环境: ubuntu LTS 18.04.1 mysql Ver 14.14 Distrib 5.7.29, for Linux (x86_64) 初探 linux,按照如下安装完mysql sudo ...

  9. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

    今天执行mysql操作的时候出现了错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run ...

随机推荐

  1. iOS开发-控件设置

    一.用户界面控件共有三种基本模式:动态.静态(非动态)和被动 动态:点击它们时会发生事情——通常是出发一段自己编写的时间代码. 被动:仅用于存储用户输入的值,以备后续使用.这些控件不会触发任何操作方法 ...

  2. TFS上使用Beyond Compare来比较源码

    In Visual Studio, go to the Tools menu, select Options, expand Source Control, (In a TFS environment ...

  3. 利用Chrome模拟访问移动端网页

    很多网站都通过User-Agent来判断浏览器类型,如果是3G手机,显示手机页面内容,如果是普通浏览器,显示普通网页内容. 谷歌Chrome浏览器,可以很方便地用来当3G手机模拟器.在Windows的 ...

  4. 【Android】Activity遮罩效果的实现

    Activity文件 package com.app.test02; import android.app.Activity; import android.graphics.Color; impor ...

  5. [MODx] 4. getResources

    1. Create a chunk call 'white_content' for white content: <!-- Highlights --> <div class=&q ...

  6. [AngularJS] Transclude -- using what existing in DOM to replace the template elements in directive

    var app = angular.module("phoneApp", []); app.controller("AppCtrl", function($sc ...

  7. eclipse代码提示框背景色改动

    因为个人习惯,喜欢把eclipse的文本编辑框背景调成全黑色,可是代码提示框的默认背景色也是黑色.所以两者就冲突了.导致看不到代码提示框的内容. 后来发现代码提示框的背景色能够改动.改动内容例如以下: ...

  8. 如何在Linux桌面环境下自动启动程序?

    大多数Linux桌面环境有各自的图形用户界面(GUI),让用户可以配置针对特定用户的自动启动程序或服务.本文将介绍如何在各种Linux桌面环境下,自动启动某个程序的方法. AD:WOT2014:用户标 ...

  9. Android(java)学习笔记123:Clock app编写报错01

    1.首先我们二话不说直接先看报错内容如下: 07-12 08:25:03.572: E/dalvikvm(3602): native fork pid:0 done. 07-12 08:25:03.5 ...

  10. DHCP服务自动分配IP地址原理

    转载自:http://blog.csdn.net/lycb_gz/article/details/8499559 DHCP在提供服务时,DHCP客户端是以UDP 68号端口进行数据传输的,而DHCP服 ...