MySQL 修改root用户密码
三种修改root用户密码的方式:
方法一: 使用set password命令
首先登录MySQL,使用mysql自带的客户端连接mysql,命令如:mysql -uroot -p
会提示你输入当前root密码,默认为空,直接回车就可以了.
格式: mysql> set password for 用户名@localhost=password('新密码');
例子: mysql> set password for root@localhost=password('666');
这里password('666')中的password会自动进行加密.
方法二:使用mysqladmin 执行管理操作的客户端程序
格式: C:\Users\Administrator>mysqladmin -u用户名 -p旧密码 password 新密码
例子: C:\Users\Administrator>mysqladmin -uroot -p666 password 新密码(也可以不输入,直接回车,提示的时候再输入,这样会安全些,别人无法通过dos下的doskey/history查看到你的新密码)
如下面的例子中的Warning: Using a password on the command line interface can be insecure. 就是安全提示
C:\Users\Administrator>mysqladmin -uroot -p666 password
Warning: Using a password on the command line interface can be insecure.
New password: ***
Confirm new password: ***
C:\Users\Administrator>doskey/history (查看历史记录命令)
mysql -uroot -p
mysqladmin -uroot -p666 password
doskey/history
方法三: update直接修改mysql库中的user表
mysql> update user set password=password('888') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
----------------------------------------------------------------忘记root密码,怎么办?----------------------------------------------------------------
这里需要重启mysqld服务端
C:\Users\Administrator>net stop mysqld
mysqld 服务正在停止.
mysqld 服务已成功停止。
C:\Users\Administrator>mysqld --skip-grant-tables (跳过用户认证权限表)
2019-06-18 10:54:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is depreca
ted. Please use --explicit_defaults_for_timestamp server option (see documentati
on for more details).
2019-06-18 10:54:24 0 [Note] --secure-file-priv is set to NULL. Operations relat
ed to importing and exporting data are disabled
2019-06-18 10:54:24 0 [Note] mysqld (mysqld 5.6.44) starting as process 2004 ...
重新打开一个dos窗口
C:\Users\Administrator>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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 |
| oldboydb |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql> use mysql;
Database changed
mysql> update user set password=password('666') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit;
Bye
C:\Users\Administrator>tasklist | findstr mysql
mysqld.exe 2004 Console 1 454,756 K
C:\Users\Administrator>taskkill /F /PID 2004
成功: 已终止 PID 为 2004 的进程。
C:\Users\Administrator>net start mysqld
mysqld 服务正在启动 .
mysqld 服务已经启动成功。
原文地址:https://www.cnblogs.com/lilyxiaoyy/p/11044205.html
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- Apache Thrift环境配置
- CentOS 7更新时出现:Multilib version problems问题的解决方法
- Linux模拟网络丢包与延迟的方法
- centos6.5通过yum安装nginx
- Linux系统利用cp命令实现强制覆盖功能的方法
- leetcode队列之设计循环双端队列
- Centos7学习之添加用户和用户组的方法
- Linux静态库与动态库实例详解
- Linux字符终端如何用鼠标移动一个红色矩形详解
- Linux中出现“No space left on device”错误的排查与解决方法
- 浏览器是如何调度进程和线程的?
- Linux shell利用sed如何批量更改文件名详解
- linux下通过xinetd服务管理 rsync 实现开机自启动
- linux实现自动删除最旧的几个文件详解
- 基于Ubuntu 16.04设置固定IP的方法教程