忘记登录mysql的密码了
# 显示的输入密码, 查看自己的报错了
mysql -u root -p123456
第一次安装使用mysql可以使用MySQL的临时密码登录进系统
# 基础linux 命令
# 查看文件内容
# | 管道符, 前者的输出作为后者的输入
# grep 包含或者说是 查找 相应 字段的行
cat /var/log/mysqld.log |grep password
每个人都不一样
当我们第一次 , 修改过以后, 就会使用我们自己的密码了, 首次登录进系统强制设置密码, 要不然啥也干不了
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> update mysql.user set authentication_string=password('123456@Y') where user='root' ;
密码有要求, 要数字,字母,符号,长度超过八位
那么当你没注意随便设置了, 就好玩了
解决方案
进入mysql的配置文件, 跳过密码检验
vi /etc/my.cnf
在 [mysqld] 配置节 下新增 skip-grant-tables
skip-grant-tables
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
"/etc/my.cnf" 29L, 979C written
就这么简单, 就跳过检验了
保存配置文件后,重启mysql服务
systemctl restart mysqld.service
使用mysql的登录命令直接回车进入即可
mysql -u root -p
# 直接回车就好
然后重新修改 mysql 的登录密码
mysql>update mysql.user set authentication_string=password('Yang@123456') where user='root' ;
mysql>flush privileges ;
mysql>quit
再次编辑mysql配置文件,
将之前添加的 skip-grant-tables 去掉。
重启mysql服务。
systemctl restart mysqld.service
参考文档 = https://www.cnblogs.com/yanziwen/p/9215264.html