出现错误 # mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql8 centos 修改root的密码
-- 1 修改 /etc/my.cnf
-- 2 添加 skip-grant-tables (跳过 登入验证)
-- 3 输入
mysql -uroot mysql;
-- 4 修改密码
use mysql;
-- 这是mysql5的命令 不可取!
-- update user set authenticate_string = password("密码") where user="用户名";
-- 限制为空
update user set authenticate_string = '' where user="root";
以上:首先:在mysql8.0以上的版本中 是没有password这个字段的。废弃了mysql5中的 password
其次:使用的aithentication_string 字段。
以上的目的是将root账户设置为不需要秘密登入。
-- 5 刷新 保存设置。
flush privileges
-- 6 退出
exit
-- 7 删除 skip-grant-tables
-- 8 登入 直接回车就好了
mysql -uroot -p;
-- 9 修改密码
use mysql;
ALTER user 'root'@'localhost' IDENTIFIED BY 'admin123'
-- 10
exit;
以上的加密方式是 mysql_native_password
查看
mysql> select host ,user,authentication_string from mysql.user ;
+-----------+------------------+----------------------------------------------------------
| host | user | authentication_string
+-----------+------------------+----------------------------------------------------------
| % | admin | *7CB4837EB74329105EE4568DDA74C67ED5CA2CD0
| localhost | root | *B17FD343E758C86BECB196715EEF742400603C5E
+-----------+------------------+----------------------------------------------------------
9 rows in set (0.00 sec)
-- % 表示可以远程连接
-- localhost 表示本地连接
标签:string,--,密码,mysql8.0,user,mysql,password,root
来源: https://blog.csdn.net/scorpio_j/article/details/112557655