Answers:
安装MySQLWorkbench,然后
export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS
source ~/.bash_profile
或加载新的终端实例。
如果您已经从http://dev.mysql.com/downloads/的磁盘映像(dmg)安装了MySQL ,请打开一个终端,运行:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
然后,.bash_profile
通过运行以下命令重新加载:
. ~/.bash_profile
您现在可以mysql
用来连接到任何mysql服务器:
mysql -h xxx.xxx.xxx.xxx -u username -p
信用和参考: http //www.gigoblog.com/2011/03/13/add-mysql-to-terminal-shell-in-mac-os-x/
最佳选择是:
brew install mysql
brew install caskroom/cask/mysql-shell
将安装命令行客户端。
mysqlsh
命令启动外壳程序。
brew install Caskroom/cask/mysql-shell
C的命令修改为“ cashroom”的大写字母,并且使用的命令是mysqlsh from
Mysql有一组仅客户端的实用程序:
MySQL客户端外壳 https://dev.mysql.com/downloads/shell/
其他命令行实用程序 https://dev.mysql.com/downloads/utilities/
提供Mac OSX版本。
mysqlsh
似乎等同于经典mysql
命令。您可以使用安装Homebrew brew cask install mysql-shell
。
mysql
提示,请尝试mysqlsh --sql
类似的体验(有用的论点大体上是相同的!)
严格地,这将安装命令行客户端,而没有其他开销:
安装Homebrew(如果没有):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后,安装mysql-client
:
brew install mysql-client
然后,将mysql-client
二进制目录添加到您的PATH中:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
最后,重新加载您的bash配置文件:
source ~/.bash_profile
然后,您应该可以mysql
在终端上运行,如果不尝试打开新终端
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
,如果使用默认的zsh(在最近的MacOS默认)
打开“ MySQL Workbench” DMG文件,然后
# Adjust the path to the version of MySQL Workbench you downloaded
cp "/Volumes/MySQL Workbench 6.3.9.CE/MySQLWorkbench.app/Contents/MacOS/mysql" /usr/local/bin
# Make sure it's executable
chmod +x /usr/local/bin/mysql
弹出DMG磁盘
cp /Applications/MySQLWorkbench.app/Contents/MacOS/mysql /usr/local/bin
ln -s /Applications/MySQLWorkbench.app/Contents/MacOS/mysql /usr/local/bin
这样就可以反映更新,而不必再次运行副本。
如前所述,您可以通过运行mysql服务器和客户端库
brew install mysql
。
也有仅客户端安装。要仅安装客户端库,请运行
brew install mysql-connector-c
为了运行这些命令,您需要在Mac中使用自制程序包管理器。您可以通过运行来安装它
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
来自brew的安装命令:
$ brew cask install mysql-shell
看你能做什么:
$ mysqlsh --help
从mysqlsh
安装的客户端运行查询:
$ mysqlsh --host=192.x.x.x --port=3306 --user=user --password=xxxxx
MySQL Shell 8.0.18
Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a session to 'user@192.x.x.x:3306'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 16
Server version: 8.0.18 MySQL Community Server - GPL
No default schema selected;
type \use <schema> to set one.
MySQL 192.x.x.x:3306 ssl JS >
MySQL 192.x.x.x:3306 ssl JS > `\use rafdb`
Default schema set to `rafdb`.
brew install mysql-client