mysql密码修改
mysql从5.7的版本开始,在你配置完data这个文件后会生成一个随机密码,第一次用这个随机密码登录进去后你执行的任何命令都没用,必须进行一次密码的修改
先使用mysql -uroot -p (“密码”)登录进去
方法一:在输入set password for ‘root’@‘localhost’ = (‘新密码’); 进行修改密码
方法二:mysqladmin -uroot -p’123456’ password # 是cmd或者shell命令
方法三:基于密码插件(mysql_secure_installation)完成修改
方法四: ALTER USER root@localhost identified by ‘123456’; # 新版本
方法五:mysql> update mysql.user set authentication_string=password(‘123456’)
-> where user=‘root’ and host=‘localhost’;
方法6:也可以使用grant这个综合性的命令完成。
grant all privileges on . to root@‘localhost’ identified by “123456”;
root密码遗忘:
关闭数据库, 修改主配置文件(/etc/my.cnf) 添加: skip-grant-tables
启动数据库, 空密码登录并修改密码
mysql> update mysql.user set authentication_string=password(‘123456’)
mysql-> where user=‘root’ and host=‘localhost’;
mysql-> flush privileges;
删除 skip-grant-tables,重启数据库验证新密码。