MySQL 地狱...无法连接到数据库 /tmp/mysql.sock

发布于 2024-10-03 11:52:44 字数 1918 浏览 1 评论 0原文

更新:我已经停止了正在运行并导致一些混乱的旧 mysql 进程。现在我想我只运行较新的(5.1.40)版本。但是,它指向错误的数据文件。它指向默认安装数据文件,我希望它指向 /var/mysql 中的现有数据文件。这是 /etc/my.cnf 的一部分,

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port        = 3306
socket      = /var/mysql/mysql.sock

它指向旧的 mysql.sock。我似乎无法在较新的 MySQL 安装的目录树中找到?!?除非是在某个不起眼的地方。

有人帮忙吗?基本上我安装了一个较新的 MySQL,现在需要让这个新版本与我现有的数据一起启动。并解决这个 mysql.sock 问题......


我最近更新了 Mac OS X Server 上的 MySQL,并且从 Rails 应用程序连接到它非常困难。或者从命令行一致地执行此操作。

我确信这对我来说是一个明显的错误,但我只有中等的命令行经验,所以希望有人可以提供帮助......

也相关的是我的 Rails 应用程序不再可以连接。无法通过 /tmp/mysql.sock 连接,但我不确定为什么它会在那里查找,因为 /tmp 中没有 mysql.sock,而且我不知道它应该在哪里/在哪里。 ...

编辑:从 mysql_config 添加结果 --sockets

$ mysql_config --sockets
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/local/mysql/include  -g -Os -arch ppc -fno-common   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL]
        --include        [-I/usr/local/mysql/include]
        --libs           [-arch ppc  -L/usr/local/mysql/lib -lmysqlclient -lz -lm     -lmygcc]
        --libs_r         [-arch ppc  -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm     -lmygcc]
        --plugindir      [/usr/local/mysql/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [5.1.40]
        --libmysqld-libs [-arch ppc  -L/usr/local/mysql/lib -lmysqld -ldl  -lz -lm       -lmygcc]

Edit2 which mysql_config

$ which mysql_config
/usr/local/mysql/bin/mysql_config

Update: I've STOPPED the older mysql process which was running and causing some confusion. Now I think I have only the newer (5.1.40) version running. BUT, it's pointing to the wrong data file. It's pointing to a default install data file and I'd like it to point to the existing data file in /var/mysql. Here's a portion of /etc/my.cnf

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port        = 3306
socket      = /var/mysql/mysql.sock

this is pointing to the older mysql.sock. I can't seem to find in the directory tree of the newer MySQL install?!? unless it's somewhere obscure.

Anyone help? Basically I installed a newer MySQL and now need to get this new version to launch with my existing data. And sort out this mysql.sock thing....


I've recently updated MySQL on Mac OS X Server and am having a hell of a time connecting to it from a rails app. or consistently from the command-line for that matter.

i'm sure this is an obvious error on my part but I only have moderate command-line experience so hoping someone can help...

also related is my rails app no longer can connect. Failing to connect via /tmp/mysql.sock but I'm not sure why it's looking there because there is no mysql.sock in /tmp and I don't know what/where it should be....

Edit: adding results from mysql_config --sockets

$ mysql_config --sockets
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/local/mysql/include  -g -Os -arch ppc -fno-common   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL]
        --include        [-I/usr/local/mysql/include]
        --libs           [-arch ppc  -L/usr/local/mysql/lib -lmysqlclient -lz -lm     -lmygcc]
        --libs_r         [-arch ppc  -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm     -lmygcc]
        --plugindir      [/usr/local/mysql/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [5.1.40]
        --libmysqld-libs [-arch ppc  -L/usr/local/mysql/lib -lmysqld -ldl  -lz -lm       -lmygcc]

Edit2 which mysql_config

$ which mysql_config
/usr/local/mysql/bin/mysql_config

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后咖啡店 2024-10-10 11:52:45

Ruby MySQL 模块中的函数 real_connect 实际上需要一堆参数:

real_connect(host,user,password,db,port,socket,flags)

您需要的参数更改的是“socket”参数。在 Mac OS X 上的 Python 应用程序上,我必须将该套接字参数设置为 /var/mysql/mysql.sock

所以请注意,您需要更改的不是主机,而是实际的套接字。是否有可以在配置中使用的 socket: 参数?

所以这就是你可以做的...

在 OS X 终端的命令行上运行命令 mysql_config --socket ,它应该返回你需要使用的“socket”的值(可能是/var/mysql/mysql.sock)。

然后在你的database.yml文件中,确保添加了这一行:

socket: /var/mysql/mysql.sock

我主要是通过OS X上的Python遇到这个问题,并以类似的方式修复它时尚,但我猜 Ruby 也会给你同样的问题。

The function real_connect in the Ruby MySQL module actually takes a bunch of parameters:

real_connect(host,user,password,db,port,socket,flags)

The one you need to change is the "socket" parameter. On my Python apps on Mac OS X, I have to set that socket parameter to be /var/mysql/mysql.sock.

So notice, it's not the host you need to change, it's the actual socket. Is there a socket: parameter you can use in your config?

So here's what you can do...

Run the command mysql_config --socket on your command line in a terminal in OS X and it should return you the value of the "socket" you need to use (probably /var/mysql/mysql.sock).

Then in your database.yml file, make sure you add the line:

socket: /var/mysql/mysql.sock

I've mostly run into this via Python on OS X and fixed it in a similar fashion, but I'm going to guess that Ruby will give you the same issue.

你与昨日 2024-10-10 11:52:44

您正在尝试为服务器和客户端使用不同的套接字。你的 Rails 正在尝试连接到 /tmp/mysql.sock,MySQL 正在监听 /var/mysql/mysql.sock。

通常 MySQL 配置存储在 /etc/my.cnf 中,但在您的 ps 输出中,我看到套接字路径作为参数给出。所以实际上取决于您系统的具体情况。

无论如何,查看 /etc/my.cnf 和你的database.yml并确保mysql.sock出现在两个文件中的相同路径中。

You are trying to use different sockets for the server and client. Your Rails is trying to connect to /tmp/mysql.sock, by MySQL is listening on /var/mysql/mysql.sock.

Normally MySQL configuration is stored in /etc/my.cnf, but in your ps your output I see socket path is given as a parameter. So really depends on your system's specifics.

Anyway, look in /etc/my.cnf and your database.yml and make sure mysql.sock appears at the same path in both files.

潜移默化 2024-10-10 11:52:44

不确定这是否能完全解决您的问题(您可能需要按照 cababunga 的建议修复套接字路径),但请尝试 127.0.0.1 绕过套接字连接并建立 TCP 连接。

Not sure whether this will completely solve your problem (you may need to fix the socket path as suggested by cababunga), but try 127.0.0.1 to bypass the socket connection and establish a TCP one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文