How to Send SQL Queries to MySQL from the Command Line
Release timeļ¼2023-05-27 23:45:27 oRead0
Method 1
Method 1 of 1:
Running without the console.
-
1
Find the mysql program (Should be in a subdirectory called bin under the directory where MySQL was installed)
- E.g. Windows users: C:\mysql\bin\mysql.exe
- E.g. Linux/Unix users: /usr/local/mysql/bin/mysql
-
2
Start mysql - At the command prompt, type: mysql -h hostname -u username -p db_name -e "query"
- where
- host is the machine where the MySQL server is running
- username is the MySQL account you want to use
- -p will make mysql prompt you for the MySQL account password.
- db_name is the name of the database to run the query in, and,
- query is the query that you want to run.
- where
- 3 Enter your password when prompted.
- 4 MySQL should return the result of your query.