A simple text program called "mysql" should have been installed along with MySQL on your PC. It allows you to send SQL queries directly to the MySQL server, and to export the results as text. It's a quick and easy way to test your MySQL installation.
Steps
Step 1. Find the mysql program (it should be in a subfolder called "bin" under the folder where MySQL was installed)
- Example for Windows users: C: / mysql / bin / mysql.exe
- Example for Linux / Unix users: / usr / local / mysql / bin / mysql
Step 2. Start mysql - When prompted, type:
mysql -h hostname -u username –p,
-
in which
- host is the machine where the MySQL server is used;
- username is the MySQL account you want to use;
- -p is used to enter the password of the MySQL account.
Step 3. Enter your password when prompted
Step 4. Type your SQL command followed by a semicolon (;) and press Enter
The response from the server should appear on the screen.
Step 5. To quit mysql, type “quit” when prompted and press Enter
Method 1 of 1: Working without a console
Step 1. Find the mysql program (it should be in a subfolder called "bin" under the folder where MySQL was installed)
- Example for Windows users: C: / mysql / bin / mysql.exe
- Example for Linux / Unix users: / usr / local / mysql / bin / mysql
Step 2. Start mysql - When prompted, type:
mysql -h hostname -u username -p db_name -e "query"
-
in which
- host is the machine where the MySQL server is used;
- username is the MySQL account you want to use;
- -p is used to enter the password of the MySQL account;
- "Db_name" is the name of the database to query, and …
- … “Query” is the query (required) you want to make.
Step 3. Enter your password when prompted
Step 4. MySQL should give you the result of the query
Advice
- Be sure to include ";" at the end of your query if you are using the console, to indicate that you are done.
- You can specify the password on the command line by putting it directly after the –p, for example “mysql -u username -h host –p password”. Note the absence of spaces between the -p and the password.
- If you are using the command line, you can use the -B label (for example: mysql -u username '-h host -p db_name -Be "query") to get the result in batch mode, rather than the default tabular mode of MySQL, for a more in-depth process.