PDF download Download Article PDF download Download Article

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.

Method 1
Method 1 of 2:

Basic Installation

PDF download Download Article
    • E.g. Windows users: C:\mysql\bin\mysql.exe
    • E.g. Linux/Unix users: /usr/local/mysql/bin/mysql
  1. 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.
    Advertisement
  2. Advertisement
Method 2
Method 2 of 2:

Running Without the Console

PDF download Download Article
    • E.g. Windows users: C:\mysql\bin\mysql.exe
    • E.g. Linux/Unix users: /usr/local/mysql/bin/mysql
  1. 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.
  2. Advertisement

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Video

Tips

  • Be sure to include; at the end of your query if you are using the console so it knows you are done with the query.
  • You can specify the password on the command line by putting it directly after the -p, e.g. mysql -u username -h host -ppassword. Notice there is no space between the -p and the password.
  • If you are running it from the command line and not using the shell, you can use the -B flag (e.g., mysql -u username' -h host -p db_name -Be "query") to get the output in batch mode, instead of in the default MySQL tabular mode, for further processing.
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

Warnings

  • Be sure you check what queries you run before you run them, as you don't want to accidentally drop a whole database!
Advertisement

You Might Also Like

Create a Database in MySQLCreate a Database in MySQL
Install phpMyAdmin on Your Windows PCInstall phpMyAdmin on Your Windows PC
Create a Secure Login Script in PHP and MySQLCreate a Secure Login Script in PHP and MySQL
Set up a Personal Web Server with XAMPPSet up a Personal Web Server with XAMPP
Run a Program on Command Prompt Run a Program at the Windows Command Prompt: 2 Ways
Install XAMPP on LinuxInstall XAMPP on Linux
Run a Program from the Command Line on LinuxRun a Program from the Command Line on Linux
Start Programming in PythonStart Programming in Python
Run an EXE File From Command PromptRun an EXE File From the Command Prompt on Windows 10 & 11
Use Windows Command Prompt to Run a Python File Use Command Prompt to Run a Python File on Windows
Reset SA Password in SQL ServerReset SA Password in SQL Server
Install XAMPP for Windows Download, Install, and Use XAMPP on Windows
Check PHP Version3 Ways to See Which Version of PHP is Installed + Troubleshooting
Open an SQL FileView and Edit SQL Files: MySQL Workbench, Excel, & More
Advertisement

About This Article

Tested by:
wikiHow Technology Team
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 12 people, some anonymous, worked to edit and improve it over time. This article has been viewed 191,928 times.
How helpful is this?
Co-authors: 12
Updated: June 5, 2025
Views: 191,928
Categories: Software
Thanks to all authors for creating a page that has been read 191,928 times.

Is this article up to date?

Advertisement