How to Send SQL Queries to MySQL from the Command Line
How to Send SQL Queries to MySQL from the Command Line
A simple text-based program called MySQL should have been part of your MySQL installation. It lets you send SQL queries directly to the MySQL server and output the results in text format. It is a quick and easy way to test your MySQL installation.
Steps

Steps

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

Start MySQL - At the command prompt, type: mysql -h hostname -u username -p, 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.

Enter your password when prompted.

Type your SQL command followed by a semi-colon (;) and press the Enter key. The response from the server should be displayed on your screen. Get out of MySQL, type quit at the prompt and press the Enter key.Send Sql Queries to Mysql from the Command Line Step 5 Version 2.jpg

Running without the console.

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

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.

Enter your password when prompted. MySQL should return the result of your query.Send Sql Queries to Mysql from the Command Line Step 9 Version 2.jpg

What's your reaction?

Comments

https://terka.info/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!