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

夙愿已清 提交于 2019-12-10 03:32:07

问题


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


回答1:


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




回答2:


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

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

or

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

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




回答3:


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

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

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



回答4:


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



回答5:


Try this on 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.

Good Luck.



来源:https://stackoverflow.com/questions/7444359/can-we-run-a-mysql-query-through-command-prompt-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!