来自 OSX 终端的 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23447695/
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 20:29:10  来源:igfitidea点击:

MySQL from OSX Terminal

mysqlmacosterminal

提问by dbconfession

I seem to be missing something as all of the tutorials that show how to run MySQL from OSX's command line aren't working.

我似乎遗漏了一些东西,因为所有展示如何从 OSX 命令行运行 MySQL 的教程都不起作用。

I can turn the MySQL Server status on and off via System preferences, but if I follow one of the tutorial that shows how to run from the command line using sudo mysqld_safeit returns the sudo: mysqld: command not found

我可以通过系统首选项打开和关闭 MySQL 服务器状态,但是如果我按照显示如何从命令行运行的教程之一使用sudo mysqld_safe它返回sudo: mysqld: command not found

I've also tried logging into MySQL using mysql -u root -pand I get bash: mysql: command not found

我也试过使用登录 MySQL mysql -u root -p,我得到bash: mysql: command not found

/usr/local/mysql/bin/does exist I just feel like something wasn't installed properly on the client side. Any help figuring out how to access mysql from the terminal would be very much appreciated. Thanks in advance.

/usr/local/mysql/bin/确实存在我只是觉得客户端没有正确安装某些东西。任何关于如何从终端访问 mysql 的帮助将不胜感激。提前致谢。

回答by zneak

/usr/local/mysql/binis not in the default $PATH. $PATHis the list of directories that are searched when you try to use an executable without specifying a complete path.

/usr/local/mysql/bin不在默认中$PATH$PATH是当您尝试使用可执行文件而不指定完整路径时搜索的目录列表。

You either need to use the full path (/usr/local/mysql/bin/mysql_executable_here) or add it to your $PATH:

您需要使用完整路径 ( /usr/local/mysql/bin/mysql_executable_here) 或将其添加到您的$PATH:

export PATH="$PATH:/usr/local/mysql/bin"

For macOS Mojave and earlier

对于 macOS Mojave 及更早版本

You can add this line to a file called .profilein your home directory to execute it each time you create a new shell:

您可以将此行添加到.profile主目录中调用的文件中,以便在每次创建新 shell 时执行它:

echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.profile
source ~/.profile
mysql -u USERNAME -p

For macOS Catalina and later

对于 macOS Catalina 及更高版本

Starting with macOS Catalina, Mac devices use zshas the default login shell and interactive shell and you have to update .zprofilefile in your home directory.

从 开始macOS Catalina,Mac 设备zsh用作默认登录 shell 和交互式 shell,您必须更新.zprofile主目录中的文件。

echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.zprofile
source ~/.zprofile
mysql -u USERNAME -p

回答by Kidane

I had this kind of problem as well. I resolved the issues like:-

我也有这样的问题。我解决了以下问题:-

  1. go to the directory cd /usr/local/mysql/bin/
  2. put this command ./mysql -u root -p;
  3. it will ask you password the root password you get at the time of installation. that way you will get your mysql connected to the database... hope that helps..
  1. 转到目录 cd /usr/local/mysql/bin/
  2. 把这个命令 ./mysql -u root -p;
  3. 它会询问您安装时获得的root密码。这样你就可以让你的 mysql 连接到数据库......希望有帮助......

回答by David Odhiambo

unless I'm missing something here, I believe you can just install mump and also run MySQL workbench. and you won't have to deal with a lot of these issues.

除非我在这里遗漏了一些东西,我相信你可以只安装 mump 并运行 MySQL 工作台。你将不必处理很多这些问题。