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...
Method 1 of 1:

Running without the console.

  1. How to Send Sql Queries to Mysql from the Command Line Picture 1How to Send Sql Queries to Mysql from the Command Line Picture 1
    Find the mysql program (Should be in a subdirectory called bin under the directory where MySQL was installed)
    1. E.g. Windows users: C:mysqlbinmysql.exe
    2. E.g. Linux/Unix users: /usr/local/mysql/bin/mysql
  2. How to Send Sql Queries to Mysql from the Command Line Picture 2How to Send Sql Queries to Mysql from the Command Line Picture 2
    Start mysql - At the command prompt, type: mysql -h hostname -u username -p db_name -e "query"
    1. where
      1. host is the machine where the MySQL server is running
      2. username is the MySQL account you want to use
      3. -p will make mysql prompt you for the MySQL account password.
      4. db_name is the name of the database to run the query in, and,
      5. query is the query that you want to run.
  3. How to Send Sql Queries to Mysql from the Command Line Picture 3How to Send Sql Queries to Mysql from the Command Line Picture 3
    Enter your password when prompted.
  4. How to Send Sql Queries to Mysql from the Command Line Picture 4How to Send Sql Queries to Mysql from the Command Line Picture 4
    MySQL should return the result of your query.
4 ★ | 1 Vote