如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:55:02  来源:igfitidea点击:

How to have "mysql" command on Mac OS?

mysqlmacos

提问by mommomonthewind

I was given a code repo which requires mysqlin command line.

我得到了一个需要mysql在命令行中使用的代码仓库。

I am using Mac OS 10.11

我使用的是 Mac OS 10.11

First, I installed MySQL Community Serverfrom http://dev.mysql.com/downloads/mysql/and install it by running the PKGfile.

首先,我MySQL Community Serverhttp://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 mysqlin 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 -poption 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 -pthen 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:

基本上这些指令是:

  1. sudo /usr/local/mysql/support-files/mysql.server stop
  2. sudo mysqld_safe --skip-grant-tables
  3. mysql -u root
  4. ALTER USER 'root'@'localhost' IDENTIFIED by 'password';
  5. FLUSH PRIVILEGES;
  6. exit
  7. sudo /usr/local/mysql/support-files/mysql.server start
  1. sudo /usr/local/mysql/support-files/mysql.server stop
  2. sudo mysqld_safe --skip-grant-tables
  3. mysql -u root
  4. ALTER USER 'root'@'localhost' IDENTIFIED by 'password';
  5. FLUSH PRIVILEGES;
  6. exit
  7. sudo /usr/local/mysql/support-files/mysql.server start

Which

哪一个

  1. Stops mysql
  2. Sets mysql to run without bothering with privileges
  3. Opens a mysql prompt
  4. Updates the root password to 'password' - you should use something else here.
  5. "Cleans" passwords (some might say this is unnecessary)
  6. Exits the mysql prompt
  7. Starts mysql
  1. 停止 mysql
  2. 将 mysql 设置为运行而无需考虑特权
  3. 打开一个 mysql 提示
  4. 将 root 密码更新为 'password' - 您应该在此处使用其他密码。
  5. “清理”密码(有些人可能会说这是不必要的)
  6. 退出mysql提示
  7. 启动mysql

That shouldallow you to run mysql -u root -pand use the new password set in #4.

应该允许您运行mysql -u root -p并使用#4 中设置的新密码。