方法一:用SET PASSWORD命令
#mysql -u root
mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘newpass‘);
方法2:用mysqladmin命令
#mysqladmin -u root password "newpass"
如果root已经设置过密码,采用如下方法
mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接编辑user表
#mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD(‘newpass‘) WHERE user = ‘root‘;
mysql> FLUSH PRIVILEGES;
方法四:用--skip-grant-tables参数启动mysqld(跳过授权表)
#mysqld_safe --skip-grant-tables &
mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user=‘root‘;
mysql> FLUSH PRIVILEGES;
建立一个具有所有权限并且可以远程连接的用户:
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘172.16.%.%‘ IDENIFIED BY ‘redhat‘;
用户的认证信息兰在内存中,改了用户的授权信息需要让mysql进程重读跟用户相关的授权信息
FLUSH PRIVILEGES