在 Mac 上设置 mysql
我首先安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要启动服务器。您应该能够运行:
您可以将其设置为在启动时运行:
有一个 有用指南以及其他细节。
You need to start the server. You should be able to run:
You can set it to run on boot with:
There is a useful guide with other details.
确保 mysqld(mysql 守护进程)确实在您的 Mac 上运行。
请记住:MySQL 是一个 SQLServer,因此它需要一个守护进程,可能监听某个 TCP 端口来处理客户端的请求。
要检查 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:
And mysql daemon process should be printed.
If it is not running, start it as stated by Mac Ports documentation.
另一个解决方案:
找出 MySQL 实际使用其 sock 的位置
通过查看您的 my.cnf 文件并查找“确保您的应用程序或任何正在使用的内容”, 。
当你连接到 Django 时你将会遇到这个问题。 MySQLdb 需要 /tmp/mysql.sock。您需要通过设置在 settings.py 文件中覆盖此设置:
Another solution:
Find out where MySQL is actually using its sock by reviewing your my.cnf file and looking for
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:
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.