MySQL 终端mysql查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11350042/
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
Terminal mysql queries
提问by Tony
I'm looking to use terminal to execute mysql queries. I currently connect to a sql db via the sql workbench but would like to do this via terminal. Is this possible?
我正在寻找使用终端来执行 mysql 查询。我目前通过 sql 工作台连接到一个 sql 数据库,但想通过终端来做到这一点。这可能吗?
I've installed mysql via homebrew
我已经通过自制软件安装了 mysql
when I hit mysql in terminal it says command not found, maybe I need to do something else besides the homebrew setup?
当我在终端中点击 mysql 时,它说找不到命令,也许除了自制软件设置之外我还需要做其他事情?
回答by Atri
Go to the directory:
进入目录:
mysql/bin
To execute the query from command line:
从命令行执行查询:
mysql -u [username] -p [dbname] -e [query]
example:
例子:
mysql -u root -p database -e "select * from user"
mysql -u root -p database -e "select * from user"
回答by pamil
mysql --help
You can do also:
你也可以这样做:
cat dump.sql | mysql -u user -p password database
Or:
或者:
echo "select * from abc;" | mysql -u user -p password database