Let's take a look at the options supported by the MySQL client program. These options control how the client program establishes a connection with the server, whether the connection is encrypted or compressed.
These options can also be given on the command line or in an options file. The below mentioned command options can be used to establish the connection -
--default-auth: This is the authentication plugin that needs to be used.
--host: The host where the MySQL server is located.
--password: The required password to use when connecting to the server.
--pipe: Used to connect to the server using named pipes. For use on Windows only.
--plugin-dir: The directory where the plug-in is installed.
- -port: TCP/IP port number to use for the connection.
--protocol: The transport protocol used.
--socket: Unix socket file or Windows named pipe to use.
--user: refers to the MySQL user name used. Used when connecting to the server.
--default-auth=plugin: It gives a hint as to which client authentication plugin must be used.
--host=host_name, -h host_name: The host where the MySQL server runs. The value can be a hostname, IPv4 address, or IPv6 address. The default value is localhost.
--password[=pass_val],-p[pass_val]: Password for the MySQL account used Connect to the server. Password value is optional.
--port=port_num, -P port_num: For TCP/IP connections, it determines the port number that needs to be used. The default port number is 3306.
--protocol={TCP|SOCKET|PIPE|MEMORY}: This option explicitly tells which transport to use A protocol must be used to connect to the server Let’s take an example -
By default, connections to localhost on Unix are made using Unix socket files. As shown below -
mysql --host=localhost
To force the use of TCP/IP transport instead of the default, the --protocol option can be specified. As shown below -
mysql --host=localhost --protocol=TCP
The above is the detailed content of Command options for connecting to MySQL server. For more information, please follow other related articles on the PHP Chinese website!