User-Profile-Image
hankin
  • 5
  • 首页
  • 分类
    • Windows
    • Web
    • VoIP
    • Virtualization
    • Trading
    • Smart Home
    • SEO
    • Security
    • Python
    • Program
    • PHP
    • OSX
    • OS
    • OpenSource
    • Nginx
    • MySQL
    • Mood
    • Linux
    • Life
    • Injection
    • Hosting
    • Finance
    • Exploits
    • CDN
  • 页面
    • About
  • 友链
    • 维酷科技
    • Tesra超算网络
Help?

Please contact us on our email for need any support

Support
  • 首页
    首页   ›   Web   ›   MySQL   ›   正文
MySQL

Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’

2010-09-17 17:43:08
5921  0 0

A frequent error message received when using the mysql command line utility is:

 Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ While this

 error message can be frustrating, the solution is simple.

When connecting to a MySQL server located on the local system, the mysql client

 connects thorugh a local file called a socket instead of connecting to the localhost

 loopback address 127.0.0.1. For the mysql client, the default location of this socket

 file is /tmp/mysql.sock. However, for a variety of reasons, many MySQL installations

 place this socket file somewhere else like /var/lib/mysql/mysql.sock. 

While it is possible to make this work by specifying the socket file directly in the

 mysql client command

mysql –socket=/var/lib/mysql/mysql.sock …

it is painful to type this in every time. If you must do so this way (because you don’t

 have permissions to the file in the solution below), you could create an alias in your

 shell to make this work (like alias mysql=”mysql –socket=/var/lib/mysql/mysql.sock”

 depending on your shell). 

To make your life easier, you can make a simple change to the MySQL configuration

 file /etc/my.cnf that will permanently set the socket file used by the mysql client. After

 making a backup copy of /etc/my.cnf, open it in your favorite editor. The file is divided

 into sections such as 

[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

If there is already a [client] section in the my.cnf file, add or edit the socket line as appropriate.

 You won’t need to restart your server or any other processes. Subsequent uses of the mysql

 client will use the proper socket file.

评论 (0)

Click here to cancel reply.

欢迎您 游客  

    ProdigYu
    180文章 77评论 4点赞 553993浏览
    随机文章
    Webpy + Nginx with FastCGI搭建Web.py
    15年前
    硬盘再次悲剧
    14年前
    CentOS安装VNC发生一个奇葩的错误
    11年前
    基于Python的socket编程
    15年前
    防止虚拟主机用户利用PHP代码DOS造成用光网络带宽
    15年前
    Tags
    Apache CentOS CMD DDOS Debian DNS Docker FastCGI Google IIS IP iptables Linux Mac MySQL Nginx Opensource PHP Python Skill SSH Ubuntu Vim VMware VPN web.py Windows 删除 命令 命令提示符 安装 开源 技巧 插件 漏洞 百度 系统 组件 终端 缓存 网络电话 脚本 自建 详解 错误
    Meta
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Copyright © 2025
    主页
    页面
    • About
    博主
    ProdigYu 管理员
    Something about myself
    180 文章 77 评论 553993 浏览
    测试
    测试