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
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 [root@DB-Server ~]# mysql -u root mysql Reading table information for completion of table and column names You 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 1 Server 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 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> use mysql Database changed mysql> 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> exit Bye
3:重新启动MySQL服务。
以上所述就是本文的全部内容了,希望大家能够喜欢
主要内容:使用mysqladmin命令在命令行指定新密码,修改MySQL数据库的user表,使用SET语句修改root用户的密码在 MySQL 中,root 用户拥有很高的权限,因此必须保证 root 用户密码的安全。修改 root 用户密码的方式有很多种,本节将介绍几种常用的修改 root 用户密码的方法。 使用mysqladmin命令在命令行指定新密码 root 用户可以使用 mysqladmin 命令来修改密码,mysqladmin 的语法格式如下: mysqladmin -u usern
本文向大家介绍MySQL 修改root密码,包括了MySQL 修改root密码的使用技巧和注意事项,需要的朋友参考一下 例子
本文向大家介绍Linux下mysql的root密码修改方法,包括了Linux下mysql的root密码修改方法的使用技巧和注意事项,需要的朋友参考一下 前言 在服务部署在mysql上应该有好几个月了,因为现在的工作基本都在终端,因此很少登陆,今天要修改个东西,忽然发现我竟然已经彻底忘记了mysql的密码,去代码里面爬终于找到了业务数据库的密码,但是root密码还是没有找到,权限没法改呀,于是开始爬
本文向大家介绍Mysql5.6忘记root密码修改root密码的方法,包括了Mysql5.6忘记root密码修改root密码的方法的使用技巧和注意事项,需要的朋友参考一下 mysql5.6忘记数据库的root密码: [root@oraserver139 ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for
本文向大家介绍CentOS环境中MySQL修改root密码方法,包括了CentOS环境中MySQL修改root密码方法的使用技巧和注意事项,需要的朋友参考一下 环境相关: OS:CentOS release 6.9 IP:192.168.1.10 MySQL:MariaDB-10.1.30 1. 修改前的确认 修改root密码是需要重启mysql库,确认生产真的可以重启mysql库; 确认生产是否
本文向大家介绍Mysql5.7忘记root密码及mysql5.7修改root密码的方法,包括了Mysql5.7忘记root密码及mysql5.7修改root密码的方法的使用技巧和注意事项,需要的朋友参考一下 关闭正在运行的 MySQL : 运行 为了安全可以这样禁止远程连接: 使用mysql连接server: 更改密码: *特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Pas