时间:2021-05-23
MySQL数据库中如何修改root用户的密码呢?下面总结了修改root用户密码的一些方法
1: 使用set password语句修改
mysql> select user();+----------------+| user() |+----------------+| root@localhost |+----------------+1 row in set (0.08 sec) mysql> set password=password('123456');Query OK, 0 rows affected (0.00 sec) mysql> flush privileges;Query OK, 0 rows affected (0.00 sec) mysql> exit2: 更新mysql数据库的user表
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A Database changedmysql> update user set password=PASSWORD('QwE123') where user='root';Query OK, 4 rows affected (0.03 sec)Rows matched: 4 Changed: 4 Warnings: 0 mysql> flush privileges;Query OK, 0 rows affected (0.00 sec) mysql> quit3:使用mysqladmin命令修改
命令一般为 mysqladmin -u root -p'oldpassword' password newpass 如下所示:
[root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123'Warning: Using a password on the command line interface can be insecure.验证root密码修改是否成功
[root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123'Warning: Using a password on the command line interface can be insecure.上面都是在知道root密码的情况下修改root密码,如果忘记了root密码,如何修改root的密码呢?
1:首先停掉MySQL服务
[root@DB-Server ~]# service mysql stopShutting down MySQL..[ OK ][root@DB-Server ~]#或
2:然后使用mysqld_safe命令启动mysql,更新root账号的密码
--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。
--skip-networking :跳过TCP/IP协议,只在本机访问(这个选项不是必须的。可以不用)是可以不用
[root@DB-Server ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &[1] 5145You have new mail in /var/spool/mail/root[root@DB-Server ~]# 150709 14:10:53 mysqld_safe Logging to '/var/lib/mysql/DB-Server.localdomain.err'.150709 14:10:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql [root@DB-Server ~]# mysql -u root mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec) mysql> use mysqlDatabase changedmysql> UPDATE user SET password=PASSWORD("Qwe123") WHERE user='root'; Query OK, 4 rows affected (0.01 sec)Rows matched: 4 Changed: 4 Warnings: 0 mysql> flush privileges;Query OK, 0 rows affected (0.00 sec) mysql> exitBye3:重新启动MySQL服务。
以上所述就是本文的全部内容了,希望大家能够喜欢
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
说到root密码,很多人想到的是电脑系统的root账号密码,其实mysql也有root密码,那么在Linux系统中,mysql要如何修改root密码呢?特别
passwd修改用户密码参数-k保持未过期身份验证令牌-l关闭账号密码。效果相当于usermod-L,只有root才有权使用此项。-u恢复账号密码。效果相当于u
在上篇文章给大家介绍了Mysql5.7忘记root密码及mysql5.7修改root密码的方法Mysql5.7忘记密码快速且简单的解决方法,具体方法详情如下所示
推荐阅读:Mysql5.7忘记root密码及mysql5.7修改root密码的方法Mac安装和卸载Mysql5.7.11的方法系统是cenos6.764位的,默
EPIC平台怎么修改账号密码?很多小伙伴都不太了解,下面小编带来修改账号密码方法介绍,希望对大家有所帮助!软件名称:EPIC游戏平台(EpicGames)V10