Home  >  Article  >  Database  >  忘mysql root密码之MYSQLADMIN修改密码方法

忘mysql root密码之MYSQLADMIN修改密码方法

WBOY
WBOYOriginal
2016-06-07 17:51:301192browse

一般出来忘记密码都是一新mysql新手朋友,下面我们来告诉你如何利用mysqadmin来把密码修改过来吧。

我来做几个例子相信很快就明白了 。
1、原来的密码是123456
C:>type 5.bat
@echo off
mysql -uroot -p123456 -P3306
正确的修改MYSQL用户密码的格式是:
我们这里用
用户:root(可以换成其他的)
密码:woshiduide
来演示新密码。

 代码如下 复制代码
C:>mysqladmin -uroot -p password woshiduide
Enter password: ******

于是修改成功。
注意PASSWORD关键字后面的空格

有好多人是这样修改的:

 代码如下 复制代码

C:>mysqladmin -uroot -p password ‘woshiduide’
Enter password: ******

C:>mysqladmin -uroot -p password ‘woshiduide’
Enter password: *********
Warning: single quotes were not trimmed from the password by your command
line client, as you might have expected.

而这个时候真正的密码是’woshiduide’

 代码如下 复制代码

C:>mysql -uroot -p’woshiduide’
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 18
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>

而新手往往这样:

 代码如下 复制代码
C:>mysql -uroot -pwoshiduide
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: Y
ES)

所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。

我现在把密码改回去。

 代码如下 复制代码
C:>mysqladmin -uroot -p’woshiduide’ password 123456

2、还有就是可以直接进入MYSQL,然后修改密码。

 代码如下 复制代码

mysql> use mysql
Database changed
mysql> update user set PASSWORD = PASSWORD(‘woshiduide’) where USER=’root’ and H
OST=’localhost’;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;

mysql> exit
Bye

C:>mysql -uroot -pwoshiduide
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 23
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>
Query OK, 0 rows affected (0.02 sec)

3、还有一种就是用SET PASSWORD 命令修改:

 代码如下 复制代码

C:>mysql5.bat
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> set password for root@’localhost’ = password(‘woshiduide’);
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)

mysql> exit
Bye
4、GRANT 也可以,不过这里不介绍。因为涉及到权限的问题。

mysql中mysqladmin命令用法简介

用于执行管理性操作。语法是:
shell>; mysqladmin [OPTIONS] command [command-option] command ...
通过执行mysqladmin --help,你可以得到你mysqladmin的版本所支持的一个选项列表。
目前mysqladmin支持下列命令:
create databasename 创建一个新
drop databasename 删除一个数据库及其所有表
extended-status 给出服务器的一个扩展状态消息
flush-hosts 洗掉所有缓存的主机
flush-logs 洗掉所有日志
flush-tables 洗掉所有表
flush-privileges 再次装载授权表(同reload)
kill id,id,... 杀死mysql线程
password 新口令,将老口令改为新口令
ping 检查mysqld是否活着
processlist 显示服务其中活跃线程列表
reload 重载授权表
refresh 洗掉所有表并关闭和打开日志文件
shutdown 关掉服务器
status 给出服务器的简短状态消息
variables 打印出可用变量
version 得到服务器的版本信息
所有命令可以被缩短为其唯一的前缀。例如:
shell>; mysqladmin proc stat
+----+-------+-----------+----+-------------+------+-------+------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+-----------+----+-------------+------+-------+------+
| 6 | monty | localhost | | Processlist | 0 | | |
+----+-------+-----------+----+-------------+------+-------+------+
Uptime: 10077 Threads: 1 Questions: 9 Slow queries: 0 Opens: 6 Flush tables: 1
Open tables: 2 Memory in use: 1092K Max memory used: 1116K
mysqladmin status命令结果有下述列:
Uptime MySQL服务器已经运行的秒数
Threads 活跃线程(客户)的数量
Questions 从mysqld启动起来自客户问题的数量
Slow queries 已经超过long_query_time秒的查询数量
Opens mysqld已经打开了多少表
Flush tables flush ..., refresh和reload命令数量
Open tables 现在被打开的表数量
Memory in use 由mysqld代码直接分配的内存(只有在MySQL用--with-debug编译时可用)
Max memory used 由mysqld代码直接分配的最大内存(只有在MySQL用--with-debug编译时可用)
主要是管理 不是使用 使用的话直接进入mysql create table
也可以mysqldmin create database
./***.sql(这里面是导出或者自己写的语句)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn