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
    • 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
2481  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
    174文章 20评论 4点赞 348982浏览
    随机文章
    aria2 — Linux 下载工具
    9年前
    PHP随机显示图片
    12年前
    wget使用技巧
    13年前
    WordPress在宝塔安装FTP环境中后台升级功能不能正常运行
    3年前
    远程桌面管理器V2.2
    9年前
    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 © 2023
    Designed by hankin
    主页
    页面
    • About
    博主
    ProdigYu 管理员
    Something about myself
    174 文章 20 评论 348982 浏览
    测试
    测试