mysql 5.7 数据库更改密码和账户授权

(1)、MySQL 5.7root用户密码修改
在MySQL 5.7 password字段已从mysql.user表中删除,新的字段名是“authenticalion_string”.
mysql>use mysql; //选择数据库
mysql>update user set authentication_string=password('password') where user='root' and Host='localhost'; //更新root密码
mysql>flush privileges; //刷新权限

mysql>grant all privileges on *.* to root@'localhost' identified by 'password' with grant option; //修改root本地密码
mysql>flush privileges;

也可以使用下面的方法来修改root用户的密码
mysql>use mysql;
mysql>set password for root@'localhost'=password('password'); // 修改root本地密码
mysql>set password for root@'%'=password('password'); // 修改root远程密码
mysql>flush privileges;

(2)、MySQL 5.7 root远程授权
mysql>grant all privileges on *.* to root@'%' identified by 'password' with grant option; // 只能更新%情形下root的密码,不能更新本机root密码
mysql>flush privileges;

(3)、破解MySQL 5.7 root密码
第一步:打开mysql5.7的配置文件my.cnf,并在里面增加一行:skip-grant-tables 保存并退出(:wq)
第二步:重启mysql : service mysqld restart
第三步: 登录mysql并且修改密码
mysql>use mysql;
mysql>update user set authentication_string = password("password") where user="root" ;
mysql>flush privileges;
第四步:打开mysql5.7的配置文件my.cnf,把刚增加这行:skip-grant-tables 删除掉 保存并退出(:wq)
第五步:重新启动mysql,即可用修改好的密码登录了。

(4)、Mysql5.7数据库初始化
# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize // 初始化数据库
初始化后登入mysql会提示
" You must reset your password using ALTER USER statement before executing this statement. ”
需要使用下面的命令来修改密码
mysql> alter user user() identified by 'password';

(5)、mysql设置复杂密码中含$特殊符号导致无法命令行登录
安全考虑 在设置MYSQL 密码时候加入了$特殊符号,导致脚本在运行时报错, 经过一番折腾发现原来就是 $导致的 果断修改密码。

相关新闻

联系我们

全国服务热线

400-033-9553

电子邮件:admin@example.com
工作时间:09:00-17:00 周一至周五

在线客服
关注微信
关注微信
分享本页
返回顶部