您的位置:首页 > 数据库 > MySQL

[mysql]MySQL修改root密码的多种方法

2017-03-22 22:21 591 查看
方法0:使用GRANT语句 
       mysql>grant all on *.* to 'root'@'localhost' IDENTIFIED BY 'newpassword' with grant option ;
       mysql>grant all on *.* to 'root'@'%' IDENTIFIED BY 'newpassword' with grant option ;
       mysql>grant all on *.* to 'root'@'192.168.1.%' IDENTIFIED BY 'newpassword' with grant option ;
       mysql>flush privileges;

方法1:
用SET PASSWORD命令
  mysql -u root
  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');

方法2:用mysqladmin
  mysqladmin -u root password "newpassword"
  如果root已经设置过密码,采用如下方法
  mysqladmin -u root password oldpass "newpassword"

方法3:
用UPDATE直接编辑user表
  mysql -u root
  mysql> use mysql;
  mysql> UPDATE user SET Password = PASSWORD('newpassword') WHERE user = 'root';
  mysql> FLUSH PRIVILEGES;

方法4:在丢失root密码的时候,可以这样
  mysqld_safe --skip-grant-tables&
  mysql -u root mysql
  mysql> UPDATE user SET password=PASSWORD("newpassword") WHERE user='root';
  mysql> FLUSH PRIVILEGES;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: