一般出來忘記密碼都是一新mysql新手朋友,下面我們來告訴你如何利用mysqadmin來把密碼修改過來吧.
我來做幾個例子相信很快就明白了.
1、原來的密碼是123456
- C:>type mysql5.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: ******
- --Vevb.com
- 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(這里面是導出或者自己寫的語句)
新聞熱點
疑難解答