加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL如何更改root账号密码

发布时间:2022-01-12 07:09:12 所属栏目:MySql教程 来源:互联网
导读:这篇文章给大家分享的是有关MySQL如何修改root账号密码的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。 MySQL数据库中如何修改root用户的密码呢?下面总结了修改root用户密码的一些方法 1: 使用set password语句修改 mysql
      这篇文章给大家分享的是有关MySQL如何修改root账号密码的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
 
      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> exit
 
2: 更新mysql数据库的user表
 
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 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> quit
 MySQL如何更改root账号密码
3:使用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 stop
Shutting down MySQL..[ OK ]
[root@DB-Server ~]#
 

 
[root@DB-Server ~]# /etc/rc.d/init.d/mysql stop
Shutting down MySQL..[ OK ]
 
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] 5145
You 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

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读