mysql-修改密码,授权远程登录,忘记密码重置

方法1: 用SET PASSWORD命令

登录[MySQL]
格式:mysql> set password for 用户名@localhost = password('新密码');

例子:mysql> set password for root@localhost = password('654321');

方法2:用mysqladmin

格式:mysqladmin -u用户名 -p旧密码 password 新密码

例子:mysqladmin -uroot -p123456 password 654321

方法3:用UPDATE直接编辑user表
mysql> use mysql; 

mysql> update user set password=password('123456') where user='root' and host='localhost'; 

mysql> flush privileges; 
方法4:重置root密码

windows

1. 关闭正在运行的MySQL服务。

2. 打开DOS窗口,转到mysql\bin目录。

3. 输入mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。

4. 再开一个DOS窗口(因为刚才那个DOS窗口已经不能动了),转到mysql\bin目录。

5. 输入mysql回车,如果成功,将出现MySQL提示符 >。

6. 连接权限数据库: use mysql; 。

6. 改密码:update user set password=password("123456") where user="root";(别忘了最后加分号) 。

7. 刷新权限(必须步骤):flush privileges; 。

8. 退出 quit。

9. 注销系统,再进入,使用用户名root和刚才设置的新密码123456登录。

Linux
在配置文件/etc/my.cnf添加配置,重启mysql
无密码登录

skip-grant-tables

客户端连接mysql选择mysql库

mysql -uroot -p
use mysql;

修改root密码5.7版本,5.7版本之后已经没有了password字段,而是用authentication_string加密字段代替

update mysql.user set authentication_string=password('123456') where user='root';

5.7版本以前

update mysql.user set password=password('123456') where user='root';
账户登录授权
1.允许root用户在任何地方进行远程登录,并具有所有库任何操作权限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES;
2.允许root用户在一个特定的IP进行远程登录,并具有所有库任何操作权限

GRANT ALL PRIVILEGES ON *.* TO [root@"192.168.1.123"]IDENTIFIED BY "password" WITH GRANT OPTION;

3.允许root用户在一个特定的IP进行远程登录,并具有所有库 特定 操作权限

GRANT select,insert,update,delete ON *.* TO [root@"192.168.1.123"] IDENTIFIED BY "password";

4.允许从192.168.1.123登录的用户yuj可以操作data库的table表,可以执行

select,insert,update,delete,create操作
mysql>grant select,insert,update,delete,create,drop on data.table to [email protected] identified by ‘123′;

你可能感兴趣的:(mysql-修改密码,授权远程登录,忘记密码重置)