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

  1. 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. 2
    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.
    Advertisement
  3. 3
    Enter your password when prompted.
  4. 4
    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.
  5. 5
    To get out of mysql, type quit at the prompt and press the Enter key.
  6. Advertisement
Method 1
Method 1 of 1:

Running without the console.

  1. 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. 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.
  3. 3
    Enter your password when prompted.
  4. 4
    MySQL should return the result of your query.
  5. 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!
    ⧼thumbs_response⧽
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, 9 people, some anonymous, worked to edit and improve it over time. This article has been viewed 180,224 times.
How helpful is this?
Co-authors: 9
Updated: October 21, 2021
Views: 180,224
Categories: Software
Advertisement