当出现此问题时,应当重置密码,步骤如下:
第一步:修改配置文件免密码登录mysql
1、vim /etc/my.cnf(当找不到该文件时,可以输入whereis my进行查询)
2、进入以后,在 [mysqld]下面加上如下语句:
skip-grant-tables
保存退出
3、重启mysql服务
service mysqld restart
第二步:免密码登录到mysql上,直接在命令行上输入以下命令:
4、mysql -u root -p(当出现password输入时,直接回车即可)
第三步: 给root用户重置密码
5、select host, user, authentication_string, plugin from user;(查看当前root用户相关信息)
6、如果root用户下的authentication_string有内容,则将其设置为空,具体操作如下(按顺序依次输入):
use mysql;
update user set authentication_string='' where user='root';
7、退出mysql, 并将刚才在/etc/my.cnf文件中添加的skip-grant-tables删除,然后重启mysql(同第3小步)
然后登陆mysql(此时仍旧是免密码登录,同第4小步)
8、重置密码,输入以下命令
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
(注意:此时的%对应的是第五步root用户的host)
mysql 8.0 的相关操作
create user 'hive'@'localhost' identified by '123456';(创建用户及密码)
grant all privileges on *.* to 'hive'@'localhost' with grant option;(给用户授权)
flush privileges;(刷新权限,授权后记得刷新)
show grants for 'hive'@'localhost';(查看用户权限)