Mysql client command line options

Source: Internet
Author: User
SpecifyProgramOption rules
    • The command name is followed by the option.
    • The option parameter starts with one or two dashes, depending on whether it has a short or long name. For example,-?And-- HelpYesMySQLThe program displays the short and long options of the help message.
    • The option name is case sensitive.-VAnd-VThey are valid, but have different meanings.(They are-- VerboseAnd-- VersionShort Name of the option).
    • Some options follow the option name followed by the option value. For example,-HlocalhostOr-- Host = localhostIndicatesMySQLServer host. The option value can tell the programMySQLThe Host Name of the server.
    • For long options with option values'='Isolate the option names and values. For short options with option values, the option values can be followed by option letters, or they can be separated by a space.(-HlocalhostAnd-H localhostIs equivalent).

The exception to the final rule is to specifyMySQLPassword options. The format of this option can be-- Password =Pass_valOr-- Password. In the latter case(No password value provided)The program prompts you to enter the password. You can also provide the password option. The short format is-PPass_valOr-P. However, for short form, if the password value is given, it must be followed by the option,Spaces cannot be inserted in the middle.. The reason for this requirement is that if there is a space behind the option, the program cannot tell the following parameter whether it is a password value or another parameter. Therefore, the following two commands have different meanings:

 
Shell> mysql-Ptestshell> Mysql-P Test

The first command causesMySQLUse PasswordTestBut no default database is specified. The second command causesMySQLPrompt for password and useTestAs the default database.

 

Connect to and disconnect the server
 
Shell> mysql-H host-u user-Penter password:********

Host and user respectively represent the Host Name and MySQL account user name running on the MySQL server. Replace the value with the correct one. * ******* Indicates your password.MySQLShow enter password: Enter it when prompted.

 

After successful connection, you can enter quit (or \ q) at the mysql> prompt to exit at any time:

 
Mysql>Quitbye

In UNIX, you can also press control-D to disconnect the server.

 

 

-E or -- execute option of MySQL

PairMySQLAnother option that is occasionally useful is-EOr-- ExecuteOption.SQLThe statement is passed to the server. This statement must be enclosed in quotation marks.(Single or double quotation marks).(However, if you want to cause a value in a query, double quotation marks should be used for the query, and single quotation marks should be used for the value referenced in the query).

When this option is used, the statement is executed and thenMySQLExit the shell immediately.

For example, you can use the following command to obtain the user account list:

Shell> mysql-u root-p-e"Select User, host from user"Mysqlenter password:* ***** + ------ + ----------- + | User | host | + ------ + ----------- + | Gigan | root | Gigan | localhost | Jon | localhost | root | localhost | + ------ + ----------- +Shell>

Note:MySQLThe database name is passed as an independent parameter. However, the same query may already be used.Mysql-u root-p-e "Select User,Host from mysql. User"Execute from shell.

 

Pass multipleSQLStatement, separated by semicolons:

Shell> mysql-u root-p -- execute ="Select name from country where name like 'au % '; select count (*) from City"Worldenter password:* ***** + ------------- + | Name | + ----------- + | Australia | Austria | + ----------- ++ ---------- + | count (*) | + ---------- + |4079| + ---------- +

Pay attention to long form(-- Execute)Followed by an equal sign(=).

 

Disable Automatic MySQL connection

IfMySQLThe client program disconnects the server when sending a query. It immediately tries to reconnect to the server and send the query again. However, even ifMySQLReconnect successful, your1Connections have also ended, and previous session objects and setting values are lost: including temporary tables, automatic submission mode, and users and session variables. This behavior is dangerous.

If necessary, terminate the connectionMySQLAnd an error is prompted. You can use-- Skip-reconnectOption to startMySQLCustomer program.

 

Execute SQL statements from text files

To achieve this, create a text fileText_fileAnd contain the statements you want to execute. CallMySQL:

 
Shell> MySQL db_name <text_file

You can also useUseDb_nameStatement to start a text file. In this case, you do not need to specify the database name in the command line:

 
Shell> mysql <text_file

If you are runningMySQL, You can useSourceOr\.Command ExecutionSQLScript file:

Mysql>Source filenamemysql> \. Filename

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.