MySQL command line connection options

Before starting the article, post a command:

root@764df9acf820:/# mysql -uroot -p

I believe that most people use it this way, and I guess that most people (the rookie me) will have a lot of questions. For example: Should there be spaces between -uroot, and what is the difference between -h and --host... Next, let's start to understand with these questions.

1. First, we understand the rules of command line parameters

  • The options are given after the command name.
  • The option parameter starts with a dash or two dashes, which are two forms of short format and long format. Such as -h and --host.
  • Option names are case sensitive. -v and -V are both legal and have different meanings. (They are the corresponding abbreviations for the –verbose and –version options.)
  • There are differences in the short format and long format followed by the parameter format.

Examples of long and short format rules are as follows:

  • The long format must start with a double dash and the parameter name is QuanPin. For example, --host=localhost is connected with = and there can be no spaces between the parameter values.
  • The short format must start with a single dash and the parameter name must be abbreviated. For example, the space between -h localhost is optional.
    Exception: There can be no spaces between the parameters -p and --possword= for specifying the password and the password. Of course, it is recommended that the password be entered after pressing Enter. If there is a parameter in the middle, the meaning is the same as -D, and the password after the space will be regarded as the specified database.
    As shown in the figure below: Go directly to the specified library.
root@764df9acf820:/# mysql -uroot -p book
Enter password:
mysql> show tables;
+------------------------+
| Tables_in_book         |
+------------------------+
| admin_menu             |

Second, the command options for establishing a connection

Options Comment For example
–user / -u Specify username -u root
–host / -h Specify the host address -h local
–password / -p Specify the connection password -ppwd
–port / -P Specify host port -P 3306
–protocol Specify the transfer protocol –protocol={TCP、SOCKET、PIPE、MEMORY}
–socket / -S Specify Unix socket file -S /tmp/mysql.sock

Usually, it is enough to master the above parameters in general use. Then we began to look at the next chapter, learn some input standby mode .

Guess you like

Origin blog.csdn.net/m0_51504545/article/details/109137786