如何在 OS X 上连接到正确的 MySQL 数据库? (两个 mysqld 实例运行)
我的机器上运行着两个 MySQL 服务器实例。一个是与 MAMP 捆绑在一起的 mysql 软件包,另一个是我下载的 64 位安装,以便我可以使用我的 python 库。
这完全是为了开发。
两者都在运行:
:~ zachary$ ps -awwx | grep mysql
1944 ?? 0:00.02 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/MyMachine-2.local.pid
2016 ?? 0:10.17 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/MyMachine-2.local.err --pid-file=/usr/local/mysql/data/MyMachine-2.local.pid
6824 ?? 0:00.02 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lower_case_table_names=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log
6894 ?? 0:00.36 /Applications/MAMP/Library/libexec/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql --user=mysql --lower_case_table_names=0 --log-error=/Applications/MAMP/logs/mysql_error_log.err --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmp/mysql/mysql.sock --port=8889
但我的 PHP 似乎只想能够连接到 MAMP 的 MySQL 服务器。我相信 mysql_connect() 可以让您指定一个端口,但我不知道如何处理这个问题。
谢谢。
编辑:当您在 MAMP 安装上使用 mysql_connect() 时,MAMP 似乎对自己的 MySQL 服务器有偏好 - 不知道为什么 - 谁能解释一下?但我能够使用以下语法连接到手动安装的 MySQL 服务器:
mysql_connect(':/tmp/mysql.sock', 'username', 'pw');
I have two instances of MySQL server running on my machine. One is the mysql package that came bundled with MAMP, and the other is a 64 bit installation that I downloaded so I could work with a python library of mine.
This is strictly for development.
Both are running:
:~ zachary$ ps -awwx | grep mysql
1944 ?? 0:00.02 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/MyMachine-2.local.pid
2016 ?? 0:10.17 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/MyMachine-2.local.err --pid-file=/usr/local/mysql/data/MyMachine-2.local.pid
6824 ?? 0:00.02 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lower_case_table_names=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log
6894 ?? 0:00.36 /Applications/MAMP/Library/libexec/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql --user=mysql --lower_case_table_names=0 --log-error=/Applications/MAMP/logs/mysql_error_log.err --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmp/mysql/mysql.sock --port=8889
Yet my PHP only seems to want to be able to connect to MAMP's MySQL server. I believe that mysql_connect() lets you specify a port but I'm not sure how to deal with this.
Thanks.
Edit: it seems that MAMP has a preference for its own MySQL server when you use mysql_connect() on a MAMP installation -- not sure why -- can anyone please explain? But I was able to connect to my manually installed MySQL server using this syntax:
mysql_connect(':/tmp/mysql.sock', 'username', 'pw');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来 MAMP 正在端口 8889 上运行,另一个实例在默认端口 (3306) 上运行。为确保安全,请运行
netstat -lnp
以查看所有侦听进程正在使用哪些端口。 (警告:仔细检查 netstat 的选项,因为我是 Linux 用户,而不是 Mac 用户)。It looks like MAMP is running on port 8889 and the other instance is on the default port (3306). To be sure, run
netstat -lnp
to see what ports all listening processes are using. (Warning: double check the options to netstat, as I am a Linux user, not a Mac user).AJ 是的。
并在特定端口(3306 除外)连接到 MySQL 服务器
AJ right.
And to connect to MySQL server on specific port (other than 3306)