Home  >  Article  >  Database  >  Multiple ways to change root password in MySQL

Multiple ways to change root password in MySQL

大家讲道理
大家讲道理Original
2016-11-12 09:54:171338browse

Method 1: Use the SET PASSWORD command

  mysql -u root
 
  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');


Method 2: Use mysqladmin
  mysqladmin -u root password "newpass"


If root has already set a password, use the following method
  mysqladmin -u root password oldpass "newpass"



Method 3: Use UPDATE to edit the user table directly
  mysql -u root
 
  mysql> use mysql;
 
  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
 
  mysql> FLUSH PRIVILEGES;


is lost When setting the root password, you can do this
  mysqld_safe --skip-grant-tables&
 
  mysql -u root mysql
 
  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
 
  mysql> FLUSH PRIVILEGES;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn