How to quickly log on to the MySQL database without a password in Shell

Source: Internet
Author: User

How to quickly log on to the MySQL database without a password in Shell

Method

The answer is yes, and MySQL has already helped us think about this problem! How to quickly log on to the MySQL database without a password in Shell

Reference link: End-User Guidelines for Password Security

Use. my. cnf to quickly log on

In ~ /Directory to create a new. my. cnf file. Of course, if you already have this file, simply modify it!

I personally like to use the vim algorithm, so we can do this.

Vim ~ /. My. cnf

Then write the following information into the file.

[Client]

Password = your_pass

User = your_user

Note: Modify your_pass and your_user the password and user name of the user you want to log on

The following is an example:

[Client]

Password = mysqlrootpassword123321

User = root

If you already have the. my. cnf file, write the information in the [client] field!

Note: Because your password is clearly written in the. my. cnf file, you must set the File Permission for this file.

Root @ imlonghao :~ # Chmod 400 ~ /. My. cnf

After saving, we can directly log on to the mysql database using the MySQL command!

Note: If you need to specify a setting file without using the default ~ /. My. cnf, you need to use the -- defaults-file = file_name parameter. Example:

Root @ imlonghao :~ # Mysql -- defaults-file =/home/imlonghao/mysql-opts

Use the environment variable MYSQL_PWD to quickly log on

MySQL uses parameters in environment variables as running parameters first.

Root @ imlonghao :~ # Export MYSQL_PWD = your_pass

After setting, you do not need to enter the password again when logging on to mysql again.

However, if you exit the current Shell, the environment variable will disappear.

Note that the commands you input in Shell will be automatically saved, and the commands you entered will be displayed in history.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.