如何在 Mac OS 上使用“mysql”命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38207610/
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
How to have "mysql" command on Mac OS?
提问by mommomonthewind
I was given a code repo which requires mysql
in command line.
我得到了一个需要mysql
在命令行中使用的代码仓库。
I am using Mac OS 10.11
我使用的是 Mac OS 10.11
First, I installed MySQL Community Server
from http://dev.mysql.com/downloads/mysql/and install it by running the PKG
file.
首先,我MySQL Community Server
从http://dev.mysql.com/downloads/mysql/安装并通过运行PKG
文件安装它。
After that, I opened System Preferences to start MySQL Server.
之后,我打开系统偏好设置来启动 MySQL 服务器。
Then, I tried to execute
然后,我尝试执行
/usr/local/mysql/bin/mysql -uroot
/usr/local/mysql/bin/mysql -uroot
and there is an error:
并且有一个错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
How could I have mysql
in command line?
我怎么能mysql
在命令行中?
Thanks,
谢谢,
回答by Jason
Typically the command is:
通常命令是:
/usr/local/mysql/bin/mysql -u root -p
which will prompt you for your root password (which might be blank unless you changed it)
这将提示您输入 root 密码(除非您更改,否则该密码可能为空)
You can also use:
您还可以使用:
/usr/local/mysql/bin/mysql -u root -p[password]
but keep in mind that password will be visible onscreen as you are typing it unlike the straight -p
option that will hide your password as you type it when prompted.
但请记住,密码将在您键入时显示在屏幕上,这与直接-p
选项不同,后者会在提示时在您键入时隐藏您的密码。
Take a look at the options for mysql: https://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html
看看mysql的选项:https: //dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html
In your case, I'd try /usr/local/mysql/bin/mysql -u root -p
then hit enter. mysql will prompt you for your password - type in in and hit enteragain. If it's wrong mysql will let you know and then you'll have to go about resetting the mysql root password.
在你的情况下,我会尝试/usr/local/mysql/bin/mysql -u root -p
然后点击enter。mysql 将提示您输入密码 - 输入并enter再次点击。如果它是错误的 mysql 会让你知道,然后你将不得不去重置 mysql root 密码。
https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/is a reasonable set of instructions for doing that in OS X (may be out of date for your version of MySQL but the comments will help) but YMMV depending on where mysql was installed, etc...
https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/是在 OS X 中执行此操作的一组合理说明(对于您的 MySQL 版本可能已过时,但注释会有所帮助) 但 YMMV 取决于 mysql 的安装位置等...
Basically those instructions are:
基本上这些指令是:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED by 'password';
FLUSH PRIVILEGES;
exit
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED by 'password';
FLUSH PRIVILEGES;
exit
sudo /usr/local/mysql/support-files/mysql.server start
Which
哪一个
- Stops mysql
- Sets mysql to run without bothering with privileges
- Opens a mysql prompt
- Updates the root password to 'password' - you should use something else here.
- "Cleans" passwords (some might say this is unnecessary)
- Exits the mysql prompt
- Starts mysql
- 停止 mysql
- 将 mysql 设置为运行而无需考虑特权
- 打开一个 mysql 提示
- 将 root 密码更新为 'password' - 您应该在此处使用其他密码。
- “清理”密码(有些人可能会说这是不必要的)
- 退出mysql提示
- 启动mysql
That shouldallow you to run mysql -u root -p
and use the new password set in #4.
这应该允许您运行mysql -u root -p
并使用#4 中设置的新密码。