Mac 安装并使用终端打开 mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14235362/
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
Mac install and open mysql using terminal
提问by Doug Fir
I downloaded the mysql dmg file and went through the wizard to run. Done. I have also started mysql server under system preferences.
我下载了 mysql dmg 文件并通过向导运行。完毕。我还在系统首选项下启动了 mysql 服务器。
The purpose of me doing this is to work through the exercises of my SQL text book. The terminal commands are new to me but I think once I can actually get started, working through the exercises should be OK.
我这样做的目的是完成我的 SQL 教科书的练习。终端命令对我来说是新的,但我认为一旦我可以真正开始,完成练习应该没问题。
From researching the web the various blogs tell me to navigate to to the mysql folder in the terminal: /usr/local/mysql
通过研究网络,各种博客告诉我导航到终端中的 mysql 文件夹:/usr/local/mysql
Fine. Then it gets a little less clear as nearly each article has a different set of instructions on how to proceed. I was fiddling with it yesterday and was prompted for a password - what is the default mysql password?
美好的。然后它变得不太清楚,因为几乎每篇文章都有一套关于如何进行的不同说明。昨天我在摆弄它并被提示输入密码 - 默认的 mysql 密码是什么?
Could someone give me the steps to get up and running with mysql via the terminal?
有人可以告诉我通过终端启动和运行 mysql 的步骤吗?
回答by Gary G
(Updated for 2017)
(2017 年更新)
When you installed MySQL it generated a password for the root user. You can connect using
当您安装 MySQL 时,它会为 root 用户生成一个密码。您可以使用连接
/usr/local/mysql/bin/mysql -u root -p
and type in the generated password.
并输入生成的密码。
Previously, the root
user in MySQL used to not have a password and could only connect from localhost. So you would connect using
以前,root
MySQL 中的用户过去没有密码,只能从 localhost 连接。所以你会使用连接
/usr/local/mysql/bin/mysql -u root
回答by knownUnknown
open terminal and type
打开终端并输入
sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
then close terminal and open a new terminal and type
然后关闭终端并打开一个新终端并输入
mysql -u root -p
hit enter, and it will ask you for password
按回车键,它会要求你输入密码
I have found this solution on https://teamtreehouse.com/community/says-mysql-command-not-found
我在https://teamtreehouse.com/community/says-mysql-command-not-found上找到了这个解决方案
now to set new password type
现在设置新密码类型
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
回答by Brad Cannell
In the terminal, I typed:
在终端中,我输入:
/usr/local/mysql/bin/mysql -u root -p
I was then prompted to enter the temporary password that was given to me upon completion of the installation.
然后提示我输入安装完成后给我的临时密码。
回答by DanTheMan
install homebrew via terminal
brew install mysql
通过终端安装自制软件
brew install mysql
回答by Cynical
If you have your MySQL server up and running, then you just need a client to connect to it and start practicing. One is the mysql-client
, which is a command-line tool, or you can use phpMyAdmin
, which is a web-based tool.
如果您的 MySQL 服务器已启动并正在运行,那么您只需要一个客户端连接到它并开始练习。一个是mysql-client
,它是一个命令行工具,或者您可以使用phpMyAdmin
,它是一个基于 Web 的工具。
回答by Bijan Negari
This command works for me:
这个命令对我有用:
./mysql -u root -p
(PS: I'm working on mac through terminal)
(PS:我正在通过终端在 mac 上工作)
回答by Micky Q
This command works for me:
这个命令对我有用:
Command:
命令:
mysql --host=localhost -uroot -proot
回答by Shivam Bharadwaj
For mac OS Catalina
:
对于 Mac 操作系统Catalina
:
/usr/local/mysql/bin/mysql -uroot -p
This will prompt you to enter password of mysql
这将提示您输入密码 mysql
回答by Elyas Hadizadeh
In MacOS, Mysql's executable file is located in /usr/local/mysql/bin/mysql
and you can easily login to it with the following command:
在 MacOS 中,Mysql 的可执行文件位于/usr/local/mysql/bin/mysql
,您可以使用以下命令轻松登录:
/usr/local/mysql/bin/mysql -u USERNAME -p
But this is a very long command and very boring, so you can add mysql path to Os's Environment variable and access to it much easier.
但是这是一个很长很无聊的命令,所以你可以将mysql路径添加到os的环境变量中,访问起来就容易多了。
For macOS Catalina
and later
对于macOS Catalina
和以后
Starting with macOS Catalina, Mac devices use zsh
as the default login shell and interactive shell and you have to update .zprofile
file 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
For macOS Mojave
and earlier
对于macOS Mojave
和更早
Although you can always switch to zsh
, bash
is the default shell in macOS Mojave and earlier and with bash
you have to update .bash_profile
file.
尽管您始终可以切换到zsh
,但它bash
是 macOS Mojave 及更早版本中的默认 shell,并且bash
您必须更新.bash_profile
文件。
echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.bash_profile
source ~/.bash_profile
mysql -u USERNAME -p
回答by Aziz Zoaib
try with either of the 2 below commands
尝试使用以下 2 个命令之一
/usr/local/mysql/bin/mysql -uroot -- OR --
/usr/local/Cellar/mysql//bin/mysql -uroot
/usr/local/mysql/bin/mysql -uroot -- 或 --
/usr/local/Cellar/mysql//bin/mysql -uroot