在 Mac 上设置 mysql

发布于 2024-09-12 14:16:46 字数 369 浏览 3 评论 0原文

我首先安装了 Macports,这样会更容易。然后安装mysql5、mysql5-server和py26-mysql。

一切顺利。当我输入:which mysql5时,它返回`/opt/local/bin/mysql5

但是当我尝试输入服务器:mysql5时,会生成错误:

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

如何修复它?

我最终希望使用 mysql 作为 django 项目的后端。 `

I first installed Macports so it would be easier. Then installed mysql5,mysql5-server and py26-mysql.

Everything went ok. When I typed: which mysql5 it returns `/opt/local/bin/mysql5

But when i try to enter the server: mysql5, an error is generated:

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

How do I fix it?

I eventually wish to use mysql as a backend to a django project.
`

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

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

发布评论

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

评论(4

温暖的光 2024-09-19 14:16:46

您需要启动服务器。您应该能够运行:

sudo /opt/local/share/mysql5/mysql/mysql.server start

您可以将其设置为在启动时运行:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

有一个 有用指南以及其他细节。

You need to start the server. You should be able to run:

sudo /opt/local/share/mysql5/mysql/mysql.server start

You can set it to run on boot with:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

There is a useful guide with other details.

花心好男孩 2024-09-19 14:16:46

确保 mysqld(mysql 守护进程)确实在您的 Mac 上运行。

请记住:MySQL 是一个 SQLServer,因此它需要一个守护进程,可能监听某个 TCP 端口来处理客户端的请求。

要检查 MySQL 守护进程是否正在运行,请在终端会话中键入:

$ ps aux | grep mysql

并且应该打印 mysql 守护进程进程。

如果它没有运行,请按照 Mac Ports 文档的说明启动它。

Make sure mysqld (mysql daemon) is actually running on your Mac.

Remember: MySQL is a SQLServer, so it needs a daemon, probably listening on some TCP port to process client's requests.

To check if MySQL daemon is running, type into a terminal session:

$ ps aux | grep mysql

And mysql daemon process should be printed.

If it is not running, start it as stated by Mac Ports documentation.

雪落纷纷 2024-09-19 14:16:46

另一个解决方案:
找出 MySQL 实际使用其 sock 的位置

socket=<your mysql sock file>

通过查看您的 my.cnf 文件并查找“确保您的应用程序或任何正在使用的内容”, 。
当你连接到 Django 时你将会遇到这个问题。 MySQLdb 需要 /tmp/mysql.sock。您需要通过设置在 settings.py 文件中覆盖此设置:

SOCK: '<your actual sock file'>

Another solution:
Find out where MySQL is actually using its sock by reviewing your my.cnf file and looking for

socket=<your mysql sock file>

Make sure this where your app, or whatever is using.
You are going to run into this problem when you hook up to Django. MySQLdb expects /tmp/mysql.sock. You need to override this in your settings.py file by setting:

SOCK: '<your actual sock file'>
睡美人的小仙女 2024-09-19 14:16:46

https://kidcodely.wordpress.com 有一个快速简单的教程/2017/10/07/database-setup/

这将引导您完成 Mac 上的完整安装,您将在其中学习如何从终端创建数据库。

There is a quick and easy tutorial at https://kidcodely.wordpress.com/2017/10/07/database-setup/

This will take you through the full installation on a mac where you'll learn how to create databases from Terminal.

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