liunx 修改mysql的密码_Linux下修改mysql的root密码方法

本人使用的mysql版本为5.6.29.

Mysql修改root密码方法:

第一种方法:mysqladmin修改root密码:

1)新数据库,从未设置过root密码,可以使用下面命令:

# mysqladmin -u root password "newpass"  #新密码为“newpass”

Warning: Using a password on the command line interface can be insecure.

2)已经设置过root密码,想使用mysqladmin修改,使用下面命令:

[root@localhost ~]# mysqladmin -u root -pnewpass  password "redhat"   #新密码为“redhat”

Warning: Using a password on the command line interface can be insecure.

截图如下:

0bde6a06ea0de4d9dc2cd44d265de240.png

错误使用方法:

纠正网上很多博客mysqladmin修改root密码的一个错误命令:

[root@localhost ~]# mysqladmin -u root password redhat "password"

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: NO)'

注释:看到报错很多人认为权限不够,去设置权限,我也设置了然并卵.网上博客一爬十,十爬百,90%的博客都在写使用上面这条

错误的命令 #mysqladmin -u root password oldpassword "newpassword"。

第二种方法:使用set password命令:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Query OK, 0 rows affected (0.00 sec)

截图如下:

184f201178ab6bbb9fd8ed0d94b21822.png

第三种方法:使用update user直接登录数据库修改密码:

mysql> update user set password = password('newpass') where user = 'root';

Query OK, 5 rows affected (0.01 sec)

Rows matched: 5  Changed: 5  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> \q

截图如下:

ca73f28a6326fe99bc517776ec00d970.png

第四种方法:使用skip-grant-tables参数可以在my.cnf文件添加,也可以启动时添加.

1)修改my.cnf文件:

[root@localhost ~]# cat /etc/my.cnf | grep skip

skip_name_resolve=on

skip-grant-tables

[root@localhost ~]# /etc/init.d/mysqld restart

Shutting down MySQL..                                      [  OK  ]

Starting MySQL.                                            [  OK  ]

[root@localhost ~]# mysql

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

Your MySQL connection id is 1

Server version: 5.6.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> quit

Bye

截图如下:

60bbaf5ea2d16db6839b984327bea5c7.png

2)启动时添加--skip-grant-tables参数:

[root@localhost ~]# /etc/init.d/mysqld restart --skip-grant-tables

Shutting down MySQL..                                      [  OK  ]

Starting MySQL.                                            [  OK  ]

[root@localhost ~]# mysql

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

Your MySQL connection id is 1

Server version: 5.6.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> quit

Bye

截图如下:

79d686afb686c6108deae2ee35c0b006.png

注意:

下面这条命令试了十几遍也没成功,可能版本不一样吧:

#mysqld_safe --skip-grant-tables &

#没有过滤到任何参数,不确定.

[root@localhost ~]# /data/mysql/bin/mysqld_safe --help | grep skip-grant-table

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值