雪豹下的Macports mysql5设置 [英] Macports mysql5 setup under Snow Leopard

查看:84
本文介绍了雪豹下的Macports mysql5设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我是新手时,我已经设法搞定了所有安装,弄糟的是我擅长的事情.

I've managed to get my install all screwed up as I'm a newbie and messing up is what I'm good at.

1)有人可以参考一套可靠的设置说明吗?

1) Can anyone reference a credible set of setup instructions for this stuff?

2)我可以直接通过macports卸载并从头开始(密码和全部)吗?我试过了,一堆mysql目录停在了Unstall之后,WTF!?

2) Can I just uninstall and start from scratch (passwords and all) through macports? I tried and a bunch of mysql directories stuck around after the unistall, WTF!?

3)mysqld.sock需要驻留在哪里,我需要应用哪些文件设置才能使其与php5和apache2配合使用? 它位于/tmp还是/opt/local/var/run/mysql5/中? 我是否需要配置/opt/local/etc/php5/php.ini? opt/local/var/db/php5/mysql.ini? /opt/local/etc/mysql5/my.cnf?

3) Where does mysqld.sock need to reside and what file settings do I need to apply to get it playing nice with php5 and apache2 ? Does it live in /tmp or in /opt/local/var/run/mysql5/ ? Do I need to configure /opt/local/etc/php5/php.ini? opt/local/var/db/php5/mysql.ini? /opt/local/etc/mysql5/my.cnf?

4)我已经运行> sudo -u mysql mysql_install_db5.如果我再次运行它,会把我弄乱吗? 我运行mysqladmin -u root密码"mypw",并收到一条错误消息,说mysql无法通过套接字连接.那么这是否意味着我的密码已经设置好了?有什么办法可以告诉我吗?

4) I've run > sudo -u mysql mysql_install_db5. If I run it again will it mess me up? I ran mysqladmin -u root password 'mypw' and got an error saying the mysql could not connect through the socket. So does this mean my password is now set? Is there a way I can tell?

5)密码声明的语法在博客之间变化.我的密码是"mypw"还是"mypw"(不带引号)? (我的密码实际上不是mypw)

5) The syntax of the password statement changes from blog to blog. Is my password 'mypw' or mypw (without the quotes)? (My password is not actually mypw)

6)启动和停止mysql的适当命令是什么?我不希望它在我的机器启动时启动.

6) What are the appropriate commands to start and stop mysql? I DO NOT want it to start when my machine starts.

感谢Jergason,这非常有帮助.

Thanks Jergason, that's tremendously helpful.

我真的想与mysql的macports安装保持一致,因为它限制了我对计算机可能造成的损害.

I'd really like to stay consistent with the macports installation of mysql since it limits the damage I can do to my machine.

所以现在悬而未决的问题是...

So the outstanding questions now are...

1)macports mysql安装的默认套接字位置是什么?

1) What is the default socket location for the macports mysql install?

2)启动和停止mysql的适当命令是什么?我不希望它在我的机器启动时启动.一些博客说使用launchctl -load,其他博客说sudo/path/mysql_safe5.如果您没有设置密码(因为我不打算这样做),是否需要使用-user -p参数?

2) What are the appropriate commands to start and stop mysql? I DO NOT want it to start when my machine starts. Some blogs say to use launchctl -load others say sudo /path/mysql_safe5. If you havn't set the password (as I don't intend to) do you need to use the -user -p parameters?

3)要使macports mysql工作,必需的目录所有权和权限是什么.似乎macports对此没有任何设置.

3) What are the necessary directory ownerships and permissions to get macports mysql working. It doesn't seem that macports sets any of that.

小猪

检查/tmp是否有MacPorts mysql套接字

Check /tmp for the MacPorts mysql socket

没有帮助.如前所述,我知道/tmp是套接字的默认位置.我的问题是,当我尝试启动mysql时,套接字未在其中实现,也未出现在/opt/local/var/run/mysql5/中.这告诉我我在启动mysql时遇到问题,这意味着设置有问题.可能是什么,我不知道.恐怕我不是天生就有这类知识的.

Not helpful. As previously stated, I understand that /tmp is the default location for the socket. My problem is that when I attempt to start mysql the socket does not materialize there, nor does it appear in /opt/local/var/run/mysql5/. This tells me I have a problem starting mysql, which means there is something wrong with the setup. What it could be, I don't know. I'm afraid I wasn't born with an a priori knowledge of such things.

-在Snow Leopard下使用macports进行mysql5安装时,套接字应位于哪个特定目录?

-What SPECIFIC directory SHOULD the socket be in for the mysql5 install using macports under Snow Leopard?

如果您使用5个不同的站点有关如何运行mysql的提示,并且您感到惊讶,您迷路了……好吧,我将其保留为尝试一次只跟踪一个站点并退出所有更改,然后再转到下一个.

If you're using 5 different sites' tips on how to run mysql and you're surprised you've gotten lost … well, I'll just leave it at try to follow just one site at a time and back out all changes before going to the next.

没有帮助.我完全按照您的建议开始.您认为我做了什么,混合搭配了5个博客的说明?这就是为什么我询问干净卸载的原因.我想知道以前安装的状态更改是否会影响将来的全新"安装.

Not helpful. I did exactly what you're suggesting to begin with. What do you think I did, mix and match instructions from 5 blogs? This is why I asked about clean uninstalls. I wanted to know if a state change from a previous install could effect future "clean" installs.

-哪个SPECIFIC博客描述了在Snow Leopard下使用macports进行的mysql5正确安装过程的确认.

-What SPECIFIC blog describes the confirmed-to-be-correct install procedure of mysql5 using macports under Snow Leopard.

我认为MacPorts mysql唯一的问题(您有什么问题?)是它有一个您不希望使用的套接字,并且使用的是默认配置.

I think the only problem you're having with MacPorts mysql (what problem are you having??) is that it's got a socket where you don't expect it and it's using a default configuration.

没有帮助.我也是,请参阅我的原始帖子.我认为问题在于mysql是如何启动(或未启动)的.

Not helpful. Me too, see my original post. I think the problem lies with how mysql is started (or isn't starting).

-您是否有关于如何解决该问题的具体建议?

-Do you have any SPECIFIC suggestions on how to correct the problem?

应该由MacPorts完成安装后对此进行了解释.

This should have been explained after the install was completed by MacPorts.

没有帮助.不是,或者我没有看到它是否是.也许是因为我在使用Porticus.

Not helpful. It wasn't, or I didn't see it if it was. Maybe because I was using Porticus.

-您能具体一点吗?我应该在什么时候看到什么消息?

-Could you be more SPECIFIC? At WHAT point should I have seen WHAT message?

请参阅$ {prefix}/share/doc/mysql5/了解想法和/或联系开发人员列表.还可以考虑与港口的维护者联系;他们可能最了解它,因为他们对此有所了解.

Please see ${prefix}/share/doc/mysql5/ for ideas and/or contact the developer list. Also consider contacting the maintainer of the port; they likely know the most about it since they manage it.

没有帮助. RTM,Google是您的朋友,等等.是的,先去那里.尽管我承认我可能已经忽略了某些事情,因为当我确定自己的问题很简单时,当我有其他工作要做时,我不愿意花几天时间阅读一些写得不好的文档.

Not helpful. RTM, Google is your friend, and all that. Yep, went there first. Although I will admit I may have overlooked something as I'm not inclined to spend days reading some poorly written docs when I have other work to do to when I'm sure my problem is a simple one.

  • 如果您想给我一个我可能忽略了的特定文档,那将很有帮助.

我希望能得到一些简单,集中的帮助,例如Jergason提供的帮助.我(和其他阅读此书的人)赞赏Jergason愿意传达他的知识,以便加快新技术人们的学习过程.对他来说,知识是基础,但对新手而言,这是一个节省大量时间的时间.智慧的真正标志是,理解技术知识不是先验的,甚至基本的帮助也将是极大的帮助.再次感谢J-man.

I was hoping for some simple, focused help like what Jergason provided. I (and others reading this) appreciate Jergason's willingness to convey his knowledge in order to accelerate the learning process of people new to various technologies. To him, the knowledge is basic, but to new-comers it's a massive time-saver. The true mark of intelligence is the understanding that technology knowledge is not a priori and that even basic help is of great help. Thanks again J-man.

推荐答案

我自己安装了mysql5,由于这总是很痛苦,因此我注意到了我遵循的过程.这是在Leopard上完成的,但是我想在Snow Leopard和Lion上的过程是相同的.它并不能回答所有最初的问题,但至少可以作为指导.

I've just installed mysql5 myself, and since this is always a pain I've noted the process that I followed. This was done on Leopard, but I imagine the process is the same on Snow Leopard and Lion. It doesn't answer all the original questions, but at least it's something of a guide.

首先,使用以下命令安装mysql5服务器:

First, install mysql5 server with:

sudo port install mysql5-server

仅安装mysql5不会安装服务器.

Just installing mysql5 doesn't install the server.

请注意控制台输出,其中包括有关设置Macport的说明.您可能需要将其复制并粘贴到文本文件中.以下是基于此的.

Pay attention to the console output, it includes instructions for setting up macports. You might want to copy and paste it to a text file. The following is based on it.

您可以使用端口(例如mysql55-servermysql56-servermariadb-serverpercona-server)代替mysql5-server,以获得更新版本的mysql或fork.如果这样做,请注意控制台输出,因为以下说明基于mysql5-server,因此需要进行调整以使用正确的可执行文件和路径.

Instead of mysql5-server, you could use a port such as mysql55-server, mysql56-server, mariadb-server or percona-server to get a more recent version of mysql, or a fork. If you do, pay attention to the console output, as the following instructions are based on mysql5-server and will need to be adjusted to use the correct executables and paths.

如果这是新安装,请设置数据库:

If this is a new install, set up the database:

sudo -u _mysql mysql_install_db5

这会输出一些通用指令,我认为这些指令并不完全适用于macports.我认为将mysql5作为守护程序加载的最佳方法是使用macport的方法:

That outputs some generic instructions, which I don't think are entirely appropriate for macports. In my opinion the best way to load mysql5 as a daemon is to use macport's method:

sudo port load mysql5-server

与启动mysql5一样,它会永久加载它-它将在启动时运行.要稍后停止此操作:

As well as starting mysql5, this permanently loads it - it will run on boot up. To stop this later:

sudo port unload mysql5-server

如果您不想将其作为守护程序运行,则可以在命令行中运行它:

If you don't want to run it as a daemon, you can run it at the command line:

sudo /opt/local/lib/mysql5/bin/mysqld_safe

通过在命令行中登录来检查它是否正在运行:

Check that it's running by logging in at the command line:

mysql5 -u root -p

默认情况下,密码为空,因此在出现提示时只需按Enter.设置root密码:

By default, the password is empty, so just press enter when prompted. To set a root password:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'correct horse battery staple'

设置macports php和本地php安装的说明如下.

Instructions for setting up both macports php and the native php installation follow.

假设您已经安装并运行了macports php.您需要安装php5-mysql(或类似php54-mysql之类的东西,具体取决于所使用的php版本):

Assuming you've already got macports php installed and running. You need to install php5-mysql (or something like php54-mysql depending on which version of php you're using):

sudo port install php5-mysql

这将安装mysql,mysqli和pdo驱动程序.

This installs the mysql, mysqli and pdo drivers.

现在,如果没有php.ini配置文件,则将php.ini-developmentphp.ini-production复制到php.ini,然后在/opt/local/etc/php5目录中查找.现在,编辑php.ini并搜索要添加的适当行:

Now look in your /opt/local/etc/php5 directory, if you don't already have a php.ini configuration file copy either php.ini-development or php.ini-production to php.ini. Now edit php.ini and search for the appropriate lines to add:

pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock

和:

mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

和:

mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock

如果您不想配置它们,则可以在连接时在php脚本中显式设置它们.

If you don't want to configure these, you can set them explicitly in your php script when you connect.

如果连接时遇到问题,则可能需要查看附近的其他设置,然后将其与php.ini-developmentphp.ini-production进行比较以查看更改之处.

If you're having trouble connecting you might want to look at the other nearby settings, and compare with php.ini-development and php.ini-production to see what's been changed.

然后使用下面的脚本,或类似的可以测试与php连接的测试.

Then use the script below, or something similar to test that you can connect with php.

OS X的php内置了mysql和mysqli支持(但不包含pdo),因此您所需要做的就是设置macport unix套接字.默认位置为/opt/local/var/run/mysql5/mysqld.sock.在/etc/php.ini中找到正确的位置(如果还没有,请从/etc/php.ini.default复制它)以添加:

OS X's php comes with mysql and mysqli support built in (but not pdo), so all you need to do is set the macport unix socket. The default location is /opt/local/var/run/mysql5/mysqld.sock. Find the correct place in /etc/php.ini (if you don't have it already, copy it from /etc/php.ini.default) to add:

mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

和:

mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock

如果您不想配置它们,则可以在连接时在php脚本中显式设置它们.

If you don't want to configure these, you can set them explicitly in your php script when you connect.

这是一个PHP脚本,可以检查它是否可以连接.显然,您通常不会在php脚本中使用root帐户,因此您可能需要首先创建另一个mysql帐户来测试连接. PDO连接不适用于本机php,因为它没有PDO驱动程序.

Here's a php script to check that it can connect. Obviously, you won't normally use the root account in your php scripts so you might want to first create another mysql account for testing the connection. The PDO connection won't work for native php since that doesn't have PDO drivers.

<?php

$username = 'root';
$password = 'correct horse battery staple';

/* Try mysql: */

$connection = mysql_connect('localhost', $username, $password);
if ($connection === FALSE) {
    echo "Error connecting using mysql.\n\n";
    echo "Error ".mysql_errno().": ".mysql_error()."\n\n";

}
else {
    echo "Connected using mysql.\n\n";
    mysql_close($connection);
}

/* Try mysqli: */

$connection = mysqli_connect('localhost', $username, $password);
if ($connection->connect_error) {
    echo "Error connecting using mysqli:\n\n";
    echo "Error ".$connection->connect_errno.": ".$connection->connect_error."\n\n";
}
else {
    echo "Connected using mysqli.\n\n";
    $connection->close();
}

/* Try pdo:
 * Won't work for the version of php supplied with OS X. */

try {
    $pdo = new PDO('mysql:host=localhost', $username, $password);
    echo "Connected using PDO.\n\n";
    $pdo = null;
}
catch(PDOException $e) {
    echo "Error connecting using PDO:\n\n";
    echo "Error ".$e->getCode().": ".$e->getMessage()."\n\n";
}

这篇关于雪豹下的Macports mysql5设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆