MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
1PLs Company - #1Payday.Loans Agency - Loans online and near me $100-$2500 (Same Day)
Powered by MySQL
 
Home / Client Server Commands / Question No: 77

What is mysql client program and how to run it?

Answer No: 77

mysql is one of the MySQL client programs. It is a command-line program that acts as a text-based front end for the MySQL Server. It's used for issuing queries and viewing the results interactively from a terminal window.

MySQL client programs can be invoked from the command line, such as from a Windows console prompt or a Unix shell prompt. When you invoke a client program, you can specify options following the program name to control its behavior. Options also can be given in option files. Some options tell the client how to connect to the MySQL server. Other options tell the program what actions to perform.

To determine the options supported by a MySQL program, invoke it with the --help option. A full list of mysql commands can be obtained using the HELP command. For example, to find out how to use mysql, use this command:

shell> mysql --help

To run above command on Windows, you can do like below:

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql --help

To determine the version of a program, use the --version option.

shell> mysql --version

In many cases, a given option has both a long and a short form. Long options consist of a word preceded by double dashes whereas short options consist of a single letter preceded by a single dash. For example, to display a program's version number, you can use the long --version option or the short -V option. These two commands are equivalent:

shell> mysql --version
shell> mysql -V

Options are case sensitive. --version is recognized by MySQL programs, but lettercase variations such as --Version or --VERSION are not. This applies to short options as well: -V and -v are both legal options, but mean different things.

To connect to a server using a client program, the client must know upon which host the server is running. A connection may be established locally to a server running on the same host as the client program, or remotely to a server running on a different host. To connect, you also must identify yourself to the server with a username and password. The primary options for connecting to the server specify the type of connection to make and identify the MySQL account that you want to use. The following tables summarize these two sets of options.

Option                 Meaning
--protocol              The protocol to use for the connection 
--host                  The host where the server is running 
--port                  The port number for TCP/IP connections
--shared-memory-base-name       The shared-memory name for shared-memory connections
--socket                        The Unix socket filename or named-pipe name
--user                  The MySQL account username
--password              The MySQL account password

Here are some examples that show how to specify connection parameters:

  • Connect to the server using the default hostname and username values with no password:
    shell> mysql
  • Connect to the local server via shared memory (this works only on Windows). Use the default username and no password:
    shell> mysql --protocol=memory
  • Connect to the server on the local host with a username of myname, asking mysql to prompt you for a password:
    shell> mysql --host=localhost --password --user=myname
  • Connect with the same options as the previous example, but using the corresponding short option forms:
    shell> mysql -h localhost -p -u myname
  • Connect to the server at a specific IP address, with a username of myname and password of mypass:
    shell> mysql --host=192.168.1.33 --user=myname --password=mypass
  • Connect to the server on the local host, using the default username and password and compressing client/server traffic:
    shell> mysql --host=localhost --compress

After successful connection, you can select or change the default database while running mysql, issue a USE db_name statement, where db_name is the name of the database you'd like to use. The following statement makes world the default database:

mysql> USE world;

You can get current database name like below:

mysql> SELECT database();

To get all available databases, run the following command:

mysql> SHOW databases;

You may run any other valid sql statement like:

mysql> SELECT * FROM Country;

You can execute a statement directly from the command line by using the -e or --execute option. Keep in mind, no statement terminator is necessary unless the string following -e consists of multiple statements. In that case, separate the statements by semicolon characters.

shell> mysql -e "SELECT VERSION()"

To quit mysql, use q, QUIT, or EXIT:

mysql> q

Related MySQL FAQs to the Above FAQ

What-are-MySQL-client-programs What are MySQL client programs?

What-are-MySQL-non-client-utilities What are MySQL non-client utilities?

How-to-connect-mysql-client-program-with-MySQL-Server-from-the-command-line How to connect mysql client program with MySQL Server from the command line?

What-is-difference-among-mysqld-mysqladmin-mysqldump-mysqlimport-and-mysqlcheck What is difference among mysqld, mysqladmin, mysqldump, mysqlimport and mysqlcheck?

How-to-check-version-of-the-running-MySQL-Server How to check version of the running MySQL Server?

What-is----compress-or--C What is --compress or -C?

What-is-difference-among---defaults-file---defaults-extra-file-and---no-defaults What is difference among --defaults-file, --defaults-extra-file and --no-defaults?

What-is-difference-between-g-and-G-characters-in-mysql-client-program What is difference between \g and \G characters in mysql client program?

How-to-execute-statement(s)-directly-from-the-command-line How to execute statement(s) directly from the command line?

How-to-cancel-the-statement-in-mysql-client-program How to cancel the statement in mysql client program?

What-is-difference-between-Interactive-Mode-and-Batch-Mode-of-mysql-client What is difference between Interactive Mode and Batch Mode of mysql client?

How-to-run-SQL-script-files-in-mysql-client How to run SQL script files in mysql client?

How-to-execute-the-entire-script-file-regardless-of-errors-occurrence How to execute the entire script file regardless of errors occurrence?

What-does-STATUS-command-in-mysql-client What does STATUS command in mysql client?

How-to-know-MySQL-system-variables How to know MySQL system variables?

What-does-MySQL-use-its-port-by-default What does MySQL use its port by default?

What-does---safe-updates-option-in-mysql What does --safe-updates option in mysql?

What-is-sql-mode-in-MySQL-and-how-can-we-set-it What is sql mode in MySQL and how can we set it?

How-to-check-the-MySQL-running-mode How to check the MySQL running mode?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2024  www.mysqlfaqs.net
All rights reserved.