大数据兼云计算(王明龙)讲师-MYSQL-DAY15-故障处理-密码忘记

故障处理-密码忘记


更改root密码(两种方法)

1. 命令行
--------------------------------------------------
# mysqladmin -u root password 密码

2. sql 语句
--------------------------------------------------
# mysql -u root -p
mysql>use mysql
mysql>update user set Password=password('new password') where user='root';
mysql>flush privileges;


允许远程连接与访问mysql

默认Mysql只允许本地登录,所以需要修改配置文件将地址绑定给注释掉:

# vim /etc/mysql/my.cnf

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address          = 127.0.0.1 ---注释掉这一行就可以远程登录了








给用户远程访问授权(3种方式)

# mysql -u root -p

use mysql


赋予任何主机访问数据的权限
grant all privileges on *.* to root@"%" identified by "mysql" WITH grant option;


进行授权允许root用123密码从所有机器上可以登录本mysql服务器
grant all on *.* to root@"%" identified by "123";


允许root用123密码从192.168.100.254机器上可以登录本mysql服务器
grant all on *.* to root@192.168.100.254 identified by "123";

不用重启,直接更新
flush privileges;


mysql 5.7
SET PASSWORD = PASSWORD('123456');           重设密码


猜你喜欢

转载自blog.csdn.net/wangminglong1989/article/details/81562828