开发者

setting up mysql on Mac

开发者 https://www.devze.com 2023-01-10 03:46 出处:网络
I first installed Macports so it would be easier. Then installed mysql5,mysql5-server and py26-mysql.

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.soc开发者_StackOverflow社区k' (2)

How do I fix it?

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


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.

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.


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'>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号