Can we run mysql query through command line in windows?

Can I run a MySQL query from a Windows command prompt? If so, how can we do this and process the query result on the command line?

+6
source share
4 answers

Try using mysql, the MySQL command line tool with the option '--execute = statement' or '-e statement'.

+9
source

You can install the MySQL client for Windows, and then use it to send commands to the server.

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

You can use the following format type for commands

mysql db_name <script.sql> output.tab

or

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

Then enter the SQL statement, end it with ";", \ g or \ G and press "Enter".

+4
source

practical example @devarts recommendation enter your user and password and database

mysql -uUSER -pPASSWORD -e 'SHOW DATABASES;' -- list databases mysql -uUSER -pPASSWORD MyDATABASE -e 'SHOW TABLES;' -- list tables in MyDATABASE 
+1
source
 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 
+1
source

Source: https://habr.com/ru/post/897466/


All Articles