background When we want to log in to the MySQL database through mysql-client in Shell, we always need to enter the password again and again, which is very troublesome. Moreover, if your root password is highly random (LastPass is a good choice), then the cost of logging into the MySQL database once will be very high. Usually we log in to the database like this, as follows root@imlonghao:~#mysql -uroot -p Enter password: So, is there a way to log in to the database safely, simply and conveniently? method Of course the answer is yes, and MySQL has already thought about this problem for us! Reference link: End-User Guidelines for Password Security Use .my.cnf to log in quickly Create a .my.cnf file in the ~/ directory. Of course, if you already have this file, just modify it! I personally like to use vim, so we can do this vim ~/.my.cnf Then write the following information in the file [client] password=your_pass user=your_user Note: Change your_pass and your_user to the password and username of the user you want to log in. Here is an example: [client] password=mysqlrootpassword123321 user=root If you already have a .my.cnf file, just write the information in the [client] field! Note: Since your password is written in plain text in the .my.cnf file, you should pay attention to setting the file permissions for this file. root@imlonghao:~# chmod 400 ~/.my.cnf After saving, we can directly use the mysql command to log in to the MySQL database! Note: If you need to specify a settings file other than the default ~/.my.cnf, you need to use root@imlonghao:~# mysql --defaults-file=/home/imlonghao/mysql-opts Use environment variable MYSQL_PWD to log in quickly MySQL will first use the parameters in the environment variables as running parameters root@imlonghao:~# export MYSQL_PWD=your_pass After setting, you don't need to enter the password again when you log in to MySQL again. However, it should be noted that if you exit the current Shell, this environment variable will disappear. What is more important to note is that the commands you enter in the Shell will be automatically saved, and you can see the commands you have entered in history. Summarize The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Solution to multiple 302 responses in nginx proxy (nginx Follow 302)
>>: Develop a vue component that encapsulates iframe
The previous article introduced the installation ...
Preface Today, when I was using a self-written co...
Use event delegation to implement message board f...
Problem Description There is a type of query call...
Written in advance: In the following steps, you n...
Copy code The code is as follows: 1. Sina Weibo &...
Preface: In the previous article, we mainly intro...
2.1 Semanticization makes your web pages better u...
Although Microsoft provides T4 templates, I find ...
Written in front I have been writing a special to...
/******************** * Virtual File System VFS *...
Preface In MySQL, we can use the EXPLAIN command ...
SRIOV introduction, VF pass-through configuration...
Table of contents The node version does not corre...
Preface: I have often heard about database paradi...