Command Options for Connecting to the MySQL Server

MySQLMySQLi Database

Let us see the options that are supported by MySQL client programs which control how client programs establish connections to the server, whether connections are encrypted, compressed or not.

These options can also be given on the command line or in an option file. The below mentioned command options can be used for connection establishment −

  • --default-auth: It is the authentication plugin that needs to be used.

  • --host: It is the host on which MySQL server is located.

  • --password: It is the password that needs to be used when connecting to server.

  • --pipe: It is used to connect to the server using named pipe. This is used on Windows only.

  • --plugin-dir: The directory where the plugins are installed.

  • --port: It is the TCP/IP port number used for connection.

  • --protocol: It is the transport protocol that is used.

  • --socket: It is the Unix socket file or Windows named pipe that is used.

  • --user: It refers to the MySQL user name that is used while connecting to the server.

  • --default-auth=plugin: It gives a hint about which client-side authentication plugin has to uses.

  • --host=host_name, -h host_name: It is the host on which the MySQL server runs. This value can be a host name, IPv4 address, or IPv6 address. The default value is the localhost.

  • --password[=pass_val], -p[pass_val]: The password of the MySQL account used for connecting to the server. The password value is optional.

  • --port=port_num, -P port_num: It is used for TCP/IP connections, where 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 protocol has to be used to connect to the serverLet us take an example −

Connections on Unix to localhost are made using a Unix socket file by default. It is shown below −

mysql --host=localhost

To force TCP/IP transport to be used instead of the default values, a --protocol option can be specified. It is shown below −

mysql --host=localhost --protocol=TCP
Published on 09-Mar-2021 13:48:39