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