macos 在 Mac 上安装 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10741848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing MySQL on a mac
提问by sharon Hwk
i have downloaded and installed mySQL
my double clicking on its icon. It was installed successfully.
我已经下载并安装了mySQL
我的双击图标。它已成功安装。
When i goto startup and preference i see the icon of mysql added and when i click on it i see a screen where it says 'MySQL server instance is running'.
当我转到启动和首选项时,我看到添加了 mysql 的图标,当我点击它时,我看到一个屏幕,上面写着“MySQL 服务器实例正在运行”。
But when i open terminal and cd
to /usr/local/mysql
and then when i type sudo ./bin/mysqld_safe
i was prompted for a password. and i have not added a password when i installed mySQL, so i tried leaving it blank, and then i tried various passwords to login but all attempts failed.
但是当我打开终端cd
到/usr/local/mysql
,然后当我输入sudo ./bin/mysqld_safe
我被提示输入密码。我在安装 mySQL 时没有添加密码,所以我尝试将其留空,然后我尝试了各种密码登录,但所有尝试都失败了。
So now i need to know how to login to mySQL via the terminal ?
所以现在我需要知道如何通过终端登录到 mySQL?
mysql version - 5.5.24-osx10.6x86_64 my Mac OS - 10.7.3
mysql 版本 - 5.5.24-osx10.6x86_64 我的 Mac OS - 10.7.3
采纳答案by titania424
What I found installing mysql on MacOs, there are a few differences. One is that it installs it without a password. The other thing is that it by default allows for anonymous logins.
我发现在 MacO 上安装 mysql 有一些不同之处。一是它在没有密码的情况下安装它。另一件事是默认情况下它允许匿名登录。
Use this to set the password:
使用它来设置密码:
mysqladmin -u root -h localhost password yourpassword
You can remove anonymous logins this way:
您可以通过以下方式删除匿名登录:
shell> mysql -u root -p
Enter password: (enter root password here)
mysql> DROP USER ''@'localhost';
mysql> DROP USER ''@'host_name';
The other thing is that I found that the install does not modify the path variable. What I did to run mysql from the command line was to add /usr/local/mysql/bin to path by adding it to /etc/paths or /etc/paths.d . This may be what you need in order to run mysql. Like someone said in the comments, mysqld_safe is one way to start the mysql server, and it seems that is already set to run.
另一件事是我发现安装不会修改路径变量。我从命令行运行 mysql 所做的是将 /usr/local/mysql/bin 添加到路径中,方法是将其添加到 /etc/paths 或 /etc/paths.d 。这可能是您运行 mysql 所需要的。就像评论里有人说的,mysqld_safe是启动mysql服务器的一种方式,而且好像已经设置好运行了。
Here are specific instructions to add something to /etc/paths.d
以下是向 /etc/paths.d 添加内容的具体说明
$ cd /etc/paths.d
$ cat > mysql
/usr/local/bin/mysql
(and then type Ctrl-D that should put a file there)
(然后键入 Ctrl-D 应该将文件放在那里)
you may have to sudo if you do not have permissions.
如果您没有权限,您可能需要 sudo。
回答by abarnert
The sudo command, by default, lets anyone in the admin group run a command as root by giving his own password. That's why it asked for your password when you typed "sudo ./bin/mysqld_safe". It has nothing whatsoever to do with mysql.
默认情况下,sudo 命令允许 admin 组中的任何人通过提供自己的密码以 root 身份运行命令。这就是为什么当您输入“sudo ./bin/mysqld_safe”时它会要求您输入密码的原因。它与mysql没有任何关系。
If you don't have a password, you cannot use sudo in the default configuration. Either give yourself a password, or edit the sudoers file. (I would strongly suggest the former over the latter, especially if you have no idea what sudo does.)
如果您没有密码,则无法在默认配置中使用 sudo。要么给自己一个密码,要么编辑 sudoers 文件。(我强烈建议前者而不是后者,特别是如果你不知道 sudo 做什么。)
For more information, type "man sudo" (and then "man sudoers") from your Terminal.
有关更多信息,请从您的终端输入“man sudo”(然后输入“man sudoers”)。
Meanwhile, the reason "it says -bash: mysql: command not found when i type mysql in the terminal" is because you've clearly installed it into /usr/local/mysql/bin/mysql, and that isn't on your path. If it were on your path, you could have just done "sudo mysqld_safe" above, instead of "sudo ./bin/mysqld_safe". Since it's not, you have to do "./bin/mysqld_safe".
同时,“它说 -bash: mysql: command not found 当我在终端中键入 mysql”的原因是因为您已经清楚地将它安装到 /usr/local/mysql/bin/mysql 中,而这不在您的小路。如果它在你的路径上,你可以在上面完成“sudo mysqld_safe”,而不是“sudo ./bin/mysqld_safe”。既然不是,你必须做“./bin/mysqld_safe”。
For more information, consult a good primer on the Unix shell.
有关更多信息,请查阅有关 Unix shell 的优秀入门书。
Finally, if you've got the mysql daemon running, and are trying to start the client, it's "mysql" that you want to run, not "mysqld_safe".
最后,如果您已经运行了 mysql 守护进程,并且正在尝试启动客户端,那么您要运行的是“mysql”,而不是“mysqld_safe”。