MySQL database (5) _mysql database Common Operations Command

Source: Internet
Author: User

Note: The newly installed MySQL contains a root account with a blank password and an anonymous account, which is a great security risk, for some important applications we should improve security as far as possible, in this case, the anonymous account deletion, the root account setting password, the following command can be used:
Use MySQL;
Delete from User where user= ""; #删除匿名账户
Update User set Password=password (newpassword) where user=root; Set Password

1. Connect MySQL

Format: mysql-h localhost-u root-ppassword DatabaseName

Note: You can have a space before the user name , but there must be no space before the password , or let you re-enter the password. But the command line input password is clear text, general-p after the password, the return will prompt the password, when the input password will not be displayed in clear text

--Connect the machine: mysql-uroot-p--remote connection-H remote host IP address-  p port number (uppercase P) mysql-h110.110.110.110-p3306-u root-p 123

2. Change the password

Root user to modify his/her password:

Method One:     mysqladmin-uroot-p123 password ' new_password '    //123 for old password method two:    UPDATE mysql.user SET password= Password (' new_password ')           WHERE user= ' root ' and host= ' localhost ';    FLUSH privileges; method Three:    SET password=password (' New_password ');    FLUSH privileges;
Root to modify other user passwords:
Method One:    SET PASSWORD for user name @ ' IP address ' =password (' new_password ');    FLUSH privileges; method Two:    UPDATE mysql.user SET password=password (' New_password ')        WHERE user= ' user name ' and host= ' IP address ';    FLUSH privileges;
Ordinary users to modify their own password:
SET Password=password (' New_password ');
Lost root user password:
# vim/etc/my.cnf    skip-grant-tables    # service mysqld Restart    # mysql-uroot    mysql> UPDATE mysql.user SET Password=password (' New_password ')    WHERE user= ' root ' and host= ' localhost ';    mysql> FLUSH privileges;

  

MySQL database (5) _mysql database Common Operations Command

Related Article

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.