h5 mysql重设密码_mysql_root密码重置

当遗忘MySQL root密码时,可以通过编辑配置文件并重启服务来重置。具体操作包括:打开my.cnf文件,添加skip-grant-tables,重启mysqld服务,无需授权直接进入数据库,使用UPDATE命令更新root用户的密码,然后刷新权限,注释掉skip-grant-tables,再次重启服务。最后使用新密码登录。
摘要由CSDN通过智能技术生成

需求背景:

当mysql root密码忘记了可以用以下配置,修改密码。

[root@wjh5 ~]# vi /etc/my.cnf #打开mysql配置文件#

[mysqld]

port = 3306

socket = /tmp/mysql.sock

skip-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1Mo

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

# Try number of CPU's*2 for thread_concurrency

thread_concurrency = 8

skip-grant #新增一行#

[root@wjh5 ~]# service mysqld restart #重启mysql服务#

Shutting down MySQL.. SUCCESS!

Starting MySQL.. SUCCESS!

[root@wjh5 ~]# /usr/local/mysql/bin/mysql -uroot #这样就不需要授权直接进入数据库#

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

Your MySQL connection id is 1

Server version: 5.1.73-log MySQL Community Server (GPL)

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

mysql> use mysql; #使用数据库#

Database changed

mysql> update user set password=password('12345678')where user='root'; #设定新的密码#

Query OK, 3 rows affected (0.01 sec)

Rows matched: 3 Changed: 3 Warnings: 0

mysql> flush privileges; #刷新权限,不然不生效,不用重启数据库服务#

Query OK, 0 rows affected (0.01 sec)

mysql> quit #退出#

[root@wjh5 ~]#vi /etc/my.cnf #找开配置文件,把添加的skip-grant这行注释掉#

[root@wjh5 ~]# /etc/init.d/mysqld restart #重启mysql服务#

[root@wjh5 ~]# mysql -uroot #登陆#

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) #提示让用密码登陆#

[root@wjh5 ~]# mysql -uroot -p12345678 #输入刚修改的密码登陆#

刚安装完mysql,会有一个账号root,密码为空的管理员账户

mysqladmin -uroot password '123456' 给root设置一个密码

mysqladmin -uroot -p123456 password '654321'更改root密码

mysql>use mysql; #使用mysql库#

Database changed

mysql> select * from user where user='root'\G; #查看user表,可以查看用户名,密码和权限信息#

mysql -uroot -p88888888 -e "use mysql;select user,host from user where user='root'"

进入mysql如果输入错误,可以输入\c退出

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值