Linux下mysql安装成功之后临时密码登陆失败解决办法

问题描述

//需要用到的命令
Shift+:w            		//保存
Shift+:q           	 		//退出
Shift+:wq           	 	//保存编辑并退出
Shift+:q!            		//强制退出不保存
mysql -u*** -p******  		//登录mysql(*代表用户名和密码)
`grep "temporary password" /var/log/mysqld.log 

mysql安装成功之后使用上面的命令查看临时密码之后登录mysql失败

解决办法

  1. 停止mysql服务
service mysqld stop
  1. 编辑my.cnf配置文件
vi /etc/my.cnf
  1. 添加配置项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
symbolic-links=0
  1. 重启mysql服务
systemctl start mysqld
  1. 登录mysql,不需要输入密码,提示输入密码直接回车
 mysql -uroot -p
  1. 登录成功之后更改密码’引号里面的就是需要更改的密码这里以123456为例’
 ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
  1. 更改之后输入\q退出mysql
  2. 记得去my.cnf删除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

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值