Home > Database > Mysql Tutorial > Multiple ways to change root password in MySQL

Multiple ways to change root password in MySQL

大家讲道理
Release: 2016-11-12 09:54:17
Original
1386 people have browsed it

Method 1: Use the SET PASSWORD command

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


Method 2: Use mysqladmin
  mysqladmin -u root password "newpass"
Copy after login


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



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;
Copy after login


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;
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template