Method One: The simplest method, but also after installing MySQL, the system prompt method. Use Mysqladmin to complete.
shell> mysqladmin-u Root Password"newpwd"Shell> mysqladmin-u root-h host_name password"newpwd"
The double quotes behind the password are not necessary, but if the password contains spaces or some special symbols, you need to use quotation marks. Method Two: Use the MySQL inside the Set password command to complete, note must use the password () function to encrypt the settings of this newpwd, otherwise direct ='newpwd'will not take effect. However, if you use the Mysqladmin password to set a password or grant to set it, you do not need to use the password () function, because they have already called the function automatically. shell> MySQL-u Root
MySQL> SET PASSWORD for'Root'@'localhost'= PASSWORD ('newpwd'); MySQL> SET PASSWORD for'Root'@'host_name'= PASSWORD ('newpwd');
Method Three: Set the password shell directly via the Update user table> mysql-u rootmysql> UPDATE mysql.user SET Password = Password ('newpwd'), WHERE User ='Root'; MySQL>FLUSH privileges; If you forget the root password of MySQL, you can take the following steps to reset1. Kill all MySQL processes.2。 Using--skip-grant-tables Parameters Start Mysqlshell> Mysqld_safe--skip-grant-tables &3. Set a new password, the same two ways you can choose the method of a shell> mysqladmin-u root flush-privileges password"newpwd"use method One error, try to use method two. Method two MySQL> UPDATE mysql.user SET password=password ('newpwd')--WHERE user='Root'; MySQL>FLUSH privileges;4. Stop MySQL server and start with normal mode5。 OK, you can use the newly-set password.
Set the root password after installing MySQL under Linux