mysql 密码修改

注意是在centos root用户下修改 不是进入数据库修改

root为用户名,password后面是新密码,回车后输入旧密码即可

[root@pavilion 15:09 hp]# mysqladmin -u root -p password dx1101628@
进入msql 不用使用某一个数据库 直接输入下面sql
1 可以改密码 set password = ‘dx1101628;’
2 可以改密码 ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
2. 忘记密码解决:
(1) 修改mysql配置文件,跳过密码验证登录mysql
(2) 重启mysql服务,使配置文件生效
sudo vim /etc/my.cnf

My.cnf的内容

加入skip-grant-tables,如下图所示

Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software

Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

The MySQL Server configuration file.

For explanations see

http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
skip-grant-tables
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

Custom config should go here

!includedir /etc/mysql/conf.d/
root@ead900cf3b13:/# exit;
Exit

加这一句配置 可以对所有用户不验证密码登陆

MySQL5.7和之前的用户修改密码方式:
update mysql.user set authentication_string=password(“123”) where user=‘root’;
mysql -uroot -e “Set password=password(‘123’);”
mysql -uroot -p123.com -e “use mysql;update user set authentication_string=password(‘456’) where user=‘root’;”
以上三种方法在MySQL8.0以后版本中将不能使用,如果使用了将会导致在正确修改密码是报如下错误:
如遇上以上问题请使用update语句先清空authentication_string字段,然后再修改密码即可
update user set authentication_string=’’ where user=‘root’;ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;
所以特别提醒童鞋们:
MySQL8.0后请使用alter修改用户密码,因为在MySQL8.0以后的加密方式为caching_sha2_password,如果使用update修改密码会给user表中root用户的authentication_string字段下设置newpassowrd值,当再使用alter user ‘root’@‘localhost’ identified by 'newpassword’修改密码时会一直报错,必须清空后再修改,因为authentication_string字段下只能是MySQL加密后的43位字符串密码,其他的会报格式错误,所以在MySQL8.0以后能修改密码的方法只能是:ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值