我们可以通过 Windows 中的命令提示符运行 mysql 查询吗?

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

Can we run a mysql query through command prompt in windows?

mysqlcommand-linemysql5

提问by learner

Can we run MySQL query from windows command prompt? If so, how can we do that and process the query result through command prompt?

我们可以从 Windows 命令提示符运行 MySQL 查询吗?如果是这样,我们如何做到这一点并通过命令提示符处理查询结果?

回答by Devart

Try to use mysql — the MySQL command-line toolwith '--execute=statement' or '-e statement' option.

尝试使用mysql —带有“--execute=statement”或“-e statement”选项的 MySQL 命令行工具

回答by Jaydee

You can install the MySQL client for windows and then use that for sending commands to a server.

您可以为 Windows 安装 MySQL 客户端,然后使用它向服务器发送命令。

http://dev.mysql.com/doc/refman/5.0/en/mysql.html

http://dev.mysql.com/doc/refman/5.0/en/mysql.html

You can use the following type of format for commands

您可以对命令使用以下类型的格式

mysql db_name < script.sql > output.tab

mysql db_name <script.sql> output.tab

or

或者

shell> mysql --user=user_name --password=your_password db_name

shell> mysql --user=user_name --password=your_password db_name

Then type an SQL statement, end it with “;”, \g, or \G and press Enter.

然后键入一条 SQL 语句,以“;”、\g 或 \G 结尾,然后按 Enter。

回答by zzapper

practical example of @devarts recommendation enter your user & password & Database

@devarts 推荐的实际示例输入您的用户和密码和数据库

mysql -uUSER -pPASSWORD  -e 'SHOW DATABASES;' -- list databases

mysql -uUSER -pPASSWORD  MyDATABASE -e 'SHOW TABLES;' -- list tables in MyDATABASE

回答by Ravindra

Yes, We can access whole DB from command line.  
1. Connect to DB (no space between -p and password)
    mysql -h <host> -u <username> -p<password>
2. Now we can check how many db we have
   show databases;
or many more commands and even we can execute quires through command line. For more command details http://g2pc1.bu.edu/~qzpeng/manual/MySQL%20Commands.htm

回答by cristiam alberto girano corber

Try this on Windows:

在 Windows 上试试这个:

  • Open window console Run CMD
  • type/copy: mysql -h hostname -u UserName -pPassWordTogether dbNAme -e"select * from table;" > D:/file.csv
  • Easy and fast.
  • 打开窗口控制台运行CMD
  • 输入/复制:mysql -h 主机名 -u 用户名 -pPassWordTogether dbNAme -e"select * from table;" > D:/file.csv
  • 简单快捷。

Good Luck.

祝你好运。