After installing MySQL root password is set under Linux

Method One: The easiest way is After mysql, the system prompts the installation method. Use mysqladmin to complete.
shell> mysqladmin -u root password "newpwd"
shell> mysqladmin -u root -h host_name password "newpwd"

Behind the double quotes password is not required, but if the password contains spaces or special symbols, need to use quotation marks. Method 2: Using mysql inside SET PASSWORD command to complete, attention must PASSWORD () This function newpwd encryption settings, or directly = 'newpwd' does not take effect. But if use a password with mysqladmin password or use GRANT to set, do not use PASSWORD () function, because they are already automatically call the function. shell> mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

Method three: UPDATE user directly set by the password table the shell> mysql -u the root
mysql> the UPDATE the mysql.user the SET Password = PASSWORD ( 'newpwd')
-> = the WHERE the User 'the root';
mysql> the FLUSH PRIVILEGES;
if you forget the mysql root password can take the following steps to re-set
1. kill off all mysql process
2. --Skip-grant-tables using the parameter start MySQL
the shell> the mysqld_safe & --skip-grant-tables
. 3. Set a new password, the same two ways to select
a method a
shell> mysqladmin -u root flush-privileges password "newpwd"
using a given method, and to make use of two methods.
Method two
MySQL> the UPDATE the mysql.user the SET Password = PASSWORD ( 'newpwd')
-> = the WHERE the User 'the root';
MySQL> the FLUSH PRIVILEGES;
. 4. Stop mysql server, start with a normal mode
5. OK, you can set up a new password

Published 172 original articles · won praise 45 · views 40000 +

Guess you like

Origin blog.csdn.net/fish_study_csdn/article/details/103940999