mysql 修改root密码_MySQL 修改root密码

MySQL 修改root密码

环境说明:

mysql:mysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper

OS:NAME="CentOS Linux" VERSION="7 (Core)"

注意:此方法是通过配置文件,使MySQL在登录时跳过验证,所以在改密码的过程中存在风险,生产环境建议防火墙中先禁止MySQL的端口

1、停MySQL服务

[root@z mysql]# systemctl stop mysqld;

[root@z mysql]# systemctl status mysqld;

mysqld.service - MySQL Server

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

Active: inactive (dead) since Sun 2018-06-10 13:00:35 CST; 6s ago

Docs: man:mysqld(8)

http://dev.mysql.com/doc/refman/en/using-systemd.html

Process: 7567 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)

Process: 7550 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

Main PID: 7571 (code=exited, status=0/SUCCESS)

Jun 10 12:56:39 izuf6d9xxma2xa7sklzdrgz systemd[1]: Starting MySQL Server...

Jun 10 12:56:40 izuf6d9xxma2xa7sklzdrgz systemd[1]: Started MySQL Server.

Jun 10 13:00:33 izuf6d9xxma2xa7sklzdrgz systemd[1]: Stopping MySQL Server...

Jun 10 13:00:35 izuf6d9xxma2xa7sklzdrgz systemd[1]: Stopped MySQL Server.

2、修改MySQL配置文件

1、查找配置文件my.cnf文件,在mysqld配置节中添加以下配置

[mysqld]

#忘记密码时使用,该配置节会使登录时跳过密码验证

skip-grant-tables

2、登录数据库,密码不输入直接登录

[root@z mysql]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

3、进入数据库并修改密码

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update mysql.user set authentication_string=password('123456') where user='root';

mysql> flush privileges;

4、配置文件中去掉添加的配置,启动数据库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值