系统:centos7
mysql:mariaDB10.1
mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
异常起因:重新配置了mysql的默认字符集,估计是原来密码是用的旧字符集保存的,client是用了新字符集
网上的答案使用重新设置密码的方式
推荐使用以下方式,无需来回设置配置文件my.conf
#关mysql
systemctl stop mysql
#无密方式登陆mysql及修改密码
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root mysql
use mysql;
update user set password=password("新密码") where user="root"
flush privileges;
quit;
#开mysql
systemctl sart mysql
重新登陆
注意事项:
mysql5.7及以后使用下面这句更新密码
update user set authentication_string =password('newpassword') where user='root';
更新语句不一样的原因:MySql5.7及以后已经没有password字段,
mariaDB10以mysql5.5版为基础,加上移植自MySQL 5.6版的功能和自行开发的新功能
相关内容取材自博客:
http://www.jb51.net/article/82421.htm
http://www.jb51.net/article/119712.htm