简体   繁体   English

在Mac上设置mysql

[英]setting up mysql on Mac

I first installed Macports so it would be easier. 我首先安装了Macports,这样会更容易。 Then installed mysql5,mysql5-server and py26-mysql. 然后安装mysql5,mysql5-server和py26-mysql。

Everything went ok. 一切顺利。 When I typed: which mysql5 it returns `/opt/local/bin/mysql5 当我键入: which mysql5返回`/ opt / local / bin / mysql5

But when i try to enter the server: mysql5, an error is generated: 但是,当我尝试进入服务器:mysql5时,会生成错误:

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. 我最终希望使用mysql作为django项目的后端。 ` `

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. 有一个有用的指南以及其他详细信息。

Make sure mysqld (mysql daemon) is actually running on your Mac. 确保mysqld (mysql守护程序)确实在Mac上运行。

Remember: MySQL is a SQLServer, so it needs a daemon, probably listening on some TCP port to process client's requests. 请记住:MySQL是一个SQLServer,因此它需要一个守护程序,可能在某个TCP端口上侦听以处理客户端的请求。

To check if MySQL daemon is running, type into a terminal session: 要检查MySQL守护程序是否正在运行,请输入终端会话:

$ ps aux | grep mysql

And mysql daemon process should be printed. 并且应该打印mysql守护进程。

If it is not running, start it as stated by Mac Ports documentation. 如果它没有运行,请按照Mac Ports文档中的说明启动它。

Another solution: Find out where MySQL is actually using its sock by reviewing your my.cnf file and looking for 另一个解决方案:通过查看my.cnf文件并查找MySQL,找出MySQL实际在哪里使用它的袜子。

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. 当您连接到Django时,将遇到此问题。 MySQLdb expects /tmp/mysql.sock. MySQLdb需要/tmp/mysql.sock。 You need to override this in your settings.py file by setting: 您需要通过设置以下内容在settings.py文件中覆盖它:

SOCK: '<your actual sock file'>

There is a quick and easy tutorial at https://kidcodely.wordpress.com/2017/10/07/database-setup/ 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. 这将带您完成在Mac上的完整安装,您将在其中学习如何从Terminal创建数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM