
It is possible to specify connection parameters without entering them on the command line every time a client program is invoked. It can be done using any one of the way − mysql -port=13306 -host=127.0.0.1 To cause the port number to be used, force a TCP/IP connection. Lets see how it can be done − mysql -host= -port=13306 To specify a port number explicitly, the -port or -P option can be used. The command would connect to the server running on using the default port number (3306). Below is a list of MySQL command-line client commands: mysql -u username -p Connect to MySQL server mysql -u username -p database Connect to MySQL Server exit Exit mysql command-line client mysqldump -u username -p database > databackup.sql Export data using mysqldump tool mysql> system clear Clear MySQL screen console. (period) can also be mentioned as the host name.Ĭonnections to remote servers will use TCP/IP. This can be done by specifying the -pipe or -protocol=PIPE option. On Windows, MySQL client can be forced to use a named-pipe connection. Let us see with the example − Example mysql -host=127.0.0.1 The transport protocol can be explicitly mentioned using the -protocol=TCP option.


Instead of this, the IP address or name of the local server can also be mentioned. To ensure that the client makes a TCP/IP connection to the local server, ‘-host’ or ‘-h’ needs to be specified, with a host name value of 127.0.0.1 (instead of localhost). If the host is not specified or it is a localhost, a connection to the local host occurs Mysql -h localhost -u myname -ppassword mydbĬlient programs determine the type of connection that needs to be made − Let us see this with the command − mysql -host=localhost -user=myname -password=password mydb To select a default database, add a database-name argument.
Mysql command line password#
To specify the host name, user name and password specifically, provide appropriate options on the command line. Since there is no such argument, mysql selects no default database. No password is sent because neither -password nor -p has been mentioned.įor mysql, the first non-option argument is considered the name of the default database. The default user name is ODBC on Windows. It supports interactive and non-interactive use. Since there are no parameter options, the default values will be applied − mysql (from MariaDB 10.4.6, also called mariadb) is a simple SQL shell (with GNU readline capabilities). The below command invokes mysql without specifying any explicit connection parameters − mysql

This is done for clients like mysql or mysqldump. Let us understand how MySQL can be connected to the database using the command-line.
