mysql修改 密码及授权远程登录

1、法一

mysql -u root

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

 2、法二

用UPDATE直接编辑user表

  mysql -u root

  mysql> use mysql;

  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

  mysql> FLUSH PRIVILEGES;

 3、法三

丢失root密码的时候,可以这样

  mysqld_safe --skip-grant-tables&

  mysql -u root mysql

  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

  mysql> FLUSH PRIVILEGES;

4、授权用户登录数据库

授权用户,你想root使用密码从任何主机连接到mysql服务器
\GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin123' WITH GRANT OPTION;flush privileges;

如果你想允许用户root从ip为192.168.12.16的主机连接到mysql服务器 
\GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.16'   IDENTIFIED BY '123456' WITH GRANT OPTION;

 参考链接http://blog.csdn.net/a1079540945/article/details/25770527

相关推荐