6.2.2.1 Using Options on the Command Line (original) (raw)

6.2.2.1 Using Options on the Command Line

Program options specified on the command line follow these rules:

mysql -ptest  
mysql -p test  

The first command instructs mysql to use a password value of test, but specifies no default database. The second instructsmysql to prompt for the password value and to use test as the default database.

SET GLOBAL general_log = ON;  
SELECT @@GLOBAL.general_log;  

At server startup, the syntax for system variables is the same as for command options, so within variable names, dashes and underscores may be used interchangeably. For example, --general_log=ON and--general-log=ON are equivalent. (This is also true for system variables set within option files.)

mysqladmin --count=1K --sleep=10 ping  

Option values that contain spaces must be quoted when given on the command line. For example, the--execute (or -e) option can be used with mysql to pass one or more semicolon-separated SQL statements to the server. When this option is used, mysql executes the statements in the option value and exits. The statements must be enclosed by quotation marks. For example:

$> mysql -u root -p -e "SELECT VERSION();SELECT NOW()"
Enter password: ******
+------------+
| VERSION()  |
+------------+
| 8.0.19     |
+------------+
+---------------------+
| NOW()               |
+---------------------+
| 2019-09-03 10:36:48 |
+---------------------+
$>

Note

The long form (--execute) is followed by an equal sign (=).

To use quoted values within a statement, you must either escape the inner quotation marks, or use a different type of quotation marks within the statement from those used to quote the statement itself. The capabilities of your command processor dictate your choices for whether you can use single or double quotation marks and the syntax for escaping quote characters. For example, if your command processor supports quoting with single or double quotation marks, you can use double quotation marks around the statement, and single quotation marks for any quoted values within the statement.