mysql 5.7.9 初始密码_尝鲜mysql5.7.9结果root密码忘记了

操作系统版本:centos 6.6

数据库版本:mysql5.7.9

1.修改my.cnf

vi /etc/my.cfn

在末尾新起一行加入:

skip-grant-tables

2.重启数据库

service mysqld restart

3.连接数据库

mysql -uroot

4.修改mysql root 用户的密码

三行命令分别如下:

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

> flush privileges;

> quit;

5.恢复第一步中的修改

vi /etc/my.cfn

去掉第一步中加入的那行代码

由于mysql 5.7.9使用了密码过期策略(参考:Password Expiration Policy),昨晚修改完是可以用的,但今晚命令行登陆进去后随使查一行都提示:

You must reset your password using ALTER USER statement before executing this statement.

解决方法:

mysqladmin -u root -p password

Enter password:

New password:

Confirm new password:

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

上述过期策略参考的文章内容中提到的几点:

mysql> select password_expired,password_last_changed,password_lifetime from user where user='root';

+------------------+-----------------------+-------------------+

| password_expired | password_last_changed | password_lifetime |

+------------------+-----------------------+-------------------+

| N                | 2015-12-02 22:02:14   |                 0 |

+------------------+-----------------------+-------------------+

1 row in set (0.00 sec)

在default_password_lifetime文中A value of 0 disables automatic password expiration,就值为0时就是禁用自动过期;

文中说为了避免mysql的密码过期突然停止服务,请执行下面语句:

ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER

以上语句一直但执行就是将password_lifetime的值改为0

装完了默认是不能远程访问的,so...

使用“use mysql”命令,选择要使用的数据库,修改远程连接的基本信息,保存在mysql数据库中,因此使用mysql数据库。

f95489c5eb604051d9035a8fd0c865e8.png

使用“GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;”命令可以更改远程连接的设置。

8cd98d1c30ee7de3a3f268f9c393ef2f.png

使用“flush privileges;”命令刷新刚才修改的权限,使其生效。

5139a1f05592d04e35389504f630c73d.png

使用“select host,user from user;”查看修改是否成功。

ec104131b0265a88ebc7f3053c46e447.png

嗯,接着你可能想给不同的同事或业务部门分配不同的帐号或密码。okay,so...please read this.

参考:创建MySQL用户 赋予某指定库表的权限 文中创建新用户,是针对5.5版本的,5.7.9得这样创建新用户,注意:密码的字段跟文中用的不一样。

创建新用户:

insert into `mysql`.`user` (Host,User,authentication_string) values ("%","gUDvpT",PASSWORD("1234567890"));

把plouto.*(即plouto下面的所有表)的所有权限(ALL PRIVILEGES )给gUDvpT用户

GRANT ALL PRIVILEGES ON plouto.* TO 'gUDvpT'@'%' IDENTIFIED BY '1234567890' WITH GRANT OPTION;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值