mysql密碼忘記linux
linux系統重置mysql的root密碼本質上就是修改mysql的root密碼,要修改root密碼,要看具體的情況,用戶可以參考如下兩種情況 。
一、如果知道root密碼,只是更換mysql的root密碼,可以通過mysqladmin來進行修改。執行如下命令:
sudomysqladmin-uroot-ppassword"你要修改的密碼"
執行命令後,會提示用戶輸入mysql的root密碼,這時候輸入原來的mysql root密碼回車即可。
⑵ linux mysql改密碼忘記了怎麼辦
MySQL密碼的恢復方法之一
1.首先確認伺服器出於安全的狀態,也就是沒有人能夠任意地連接MySQL資料庫。
因為在重新設置MySQL的root密碼的期間,MySQL資料庫完全出於沒有密碼保護的
狀態下,其他的用戶也可以任意地登錄和修改MySQL的信息。可以採用將MySQL對外的埠封閉,並且停止Apache以及所有的用戶進程的方法實現伺服器的准安全狀態。最安全的狀態是到伺服器的Console上面操作,並且拔掉網線。
2.修改MySQL的登錄設置:
#
vi
/etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
保存並且退出vi。
3.重新啟動mysqld
#
/etc/init.d/mysqld
restart
(
service
mysqld
restart
)
4.登錄並修改MySQL的root密碼
mysql>
USE
mysql
;
mysql>
UPDATE
user
SET
Password
=
password
(
'new-password'
)
WHERE
User
=
'root'
;
mysql>
flush
privileges
;
mysql>
quit
5.將MySQL的登錄設置修改回來
#
vi
/etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存並且退出vi。
6.重新啟動mysqld
#
/etc/init.d/mysqld
restart
(
service
mysqld
restart
)
7.恢復伺服器的正常工作狀態
將步驟一中的操作逆向操作。恢復伺服器的工作狀態。
MySQL密碼的恢復方法之二
如果忘記了MySQL的root密碼,可以用以下方法重新設置:
1.
KILL掉系統里的MySQL進程;
killall
-TERM
mysqld
2.
用以下命令啟動MySQL,以不檢查許可權的方式啟動;
safe_mysqld
--skip-grant-tables
&
3.
然後用空密碼方式使用root用戶登錄
MySQL;
mysql
-u
root
4.
修改root用戶的密碼;
mysql>
update
mysql.user
set
password=PASSWORD('新密碼')
where
User='root';
mysql>
flush
privileges;
mysql>
quit
重新啟動MySQL,就可以使用新密碼登錄了
MySQL密碼的恢復方法三
有可能你的系統沒有
safe_mysqld
程序(比如我現在用的
ubuntu操作系統,
apt-get安裝的mysql)
,
下面方法可以恢復
1.
停止mysqld;
/etc/init.d/mysql
stop
(您可能有其它的方法,總之停止mysqld的運行就可以了)
2.
用以下命令啟動MySQL,以不檢查許可權的方式啟動;
mysqld
--skip-grant-tables
&
3.
然後用空密碼方式使用root用戶登錄
MySQL;
mysql
-u
root
4.
修改root用戶的密碼;
mysql>
update
mysql.user
set
password=PASSWORD('newpassword')
where
User='root';
mysql>
flush
privileges;
mysql>
quit
重新啟動MySQL
/etc/init.d/mysql
restart
就可以使用新密碼
newpassword
登錄了。
1.例如你的 root用戶現在沒有密碼,你希望的密碼修改為123456,那麼命令是:
mysqladmin -u root password 123456
2.如果你的root現在有密碼了(123456),那麼修改密碼為abcdef的命令是:
mysqladmin -u root -p password abcdef
注意,命令回車後會問你舊密碼,輸入舊密碼123456之後命令完成,密碼修改成功。
3.如果你的root現在有密碼了(123456),那麼修改密碼為abcdef的命令是:
mysqladmin -u root -p123456 password abcdef (注意-p 不要和後面的密碼分
開寫,要寫在一起,不然會出錯,錯誤如下所示)
4.使用phpmyadmin,這是最簡單的了,修改mysql庫的user表,
不過別忘了使用PASSWORD函數。
忘記密碼:
下面我們提供了6種不同的修改mysql root用戶的密碼,與增加mysql用戶的方法。
方法一:
使用phpmyadmin,這是最簡單的了,修改mysql庫的user表,
不過別忘了使用PASSWORD函數。
方法二:
使用mysqladmin,這是前面聲明的一個特例。
mysqladmin -u root -p password mypasswd
輸入這個命令後,需要輸入root的原密碼,然後root的密碼將改為mypasswd。
把命令里的root改為你的用戶名,你就可以改你自己的密碼了。
當然如果你的mysqladmin連接不上mysql server,或者你沒有辦法執行mysqladmin,
那麼這種方法就是無效的。
而且mysqladmin無法把密碼清空。
下面的方法都在mysql提示符下使用,且必須有mysql的root許可權:
方法三:
mysql> INSERT INTO mysql.user (Host,User,Password)
VALUES('%','jeffrey',PASSWORD('biscuit'));
mysql> FLUSH PRIVILEGES
確切地說這是在增加一個用戶,用戶名為jeffrey,密碼為biscuit。
在《mysql中文參考手冊》里有這個例子,所以我也就寫出來了。
注意要使用PASSWORD函數,然後還要使用FLUSH PRIVILEGES。
方法四 :
和方法三一樣,只是使用了REPLACE語句
mysql> REPLACE INTO mysql.user (Host,User,Password)
VALUES('%','jeffrey',PASSWORD('biscuit'));
mysql> FLUSH PRIVILEGES
方法五:
使用SET PASSWORD語句,
mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
擬也必須使用PASSWORD()函數,
但是不需要使用FLUSH PRIVILEGES。
方法六:
使用GRANT ... IDENTIFIED BY語句
mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
這里PASSWORD()函數是不必要的,也不需要使用FLUSH PRIVILEGES。
注意: PASSWORD() [不是]以在Unix口令加密的同樣方法施行口令加密。
MySQL 忘記口令的解決辦法
如果 MySQL 正在運行,首先殺之: killall -TERM mysqld。
啟動 MySQL :bin/safe_mysqld --skip-grant-tables &
就可以不需要密碼就進入 MySQL 了。
然後就是
>use mysql
>update user set password=password("new_pass") where user="root";
>flush privileges;
重新殺 MySQL ,用正常方法啟動 MySQL 。
其它辦法:
辦法一: 在linux下忘記mysql的密碼,咋整?有一種方法可以很快的重設密碼。
首先,關閉mysql.
這個時候你用Mysqladmin shutdown來關閉mysql基本是不可能的,為啥,因為你不知到密碼了么,用其它用戶去連接mysql庫,會提示你沒有許可權。
其次,直接用kill命令也是不行的。mysqld_safe啟動以後,如果mysqld被kill掉,這個進程會自動重啟,真是坑爹啊!
那麼,只能使出絕招了
killall -TERM mysqld
第二步,到root用戶下(或者是mysql服務的安裝用戶下)繞開安全許可權啟動mysqld
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
第三步,修改Mysql庫中的user表,重新賦予新的許可權
>use mysql
>update user set password=password("new_pass") where user="root";
>flush privileges;
注意,這步會把所有user=root的賬戶密碼都設為這個,可以在where里加入針對性的限定條件
第四步,重新kill掉mysqld,然後重啟,一切ok
辦法二:
1.首先確認伺服器出於安全的狀態,也就是沒有人能夠任意地連接MySQL資料庫。
因為在重新設置MySQL的root密碼的期間,MySQL資料庫完全出於沒有密碼保護的 狀態下,其他的用戶也可以任意地登錄和修改MySQL的信息。可以採用將MySQL對外的埠封閉,並且停止Apache以及所有的用戶進程的方法實現伺服器的准安全狀態。最安全的狀態是到伺服器的Console上面操作,並且拔掉網線。
2.修改MySQL的登錄設置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存並且退出vi。
3.重新啟動mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4.登錄並修改MySQL的root密碼
# /usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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 ( 'new-password' ) WHERE User = 'root' ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
5.將MySQL的登錄設置修改回來
# vi /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存並且退出vi。
6.重新啟動mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
⑷ linux mysql修改密碼命令
想知道linux下怎麼修改密碼嗎?下面由我為大家整理了linux mysql修改密碼命令,希望大家喜歡!
linux mysql修改密碼命令
1.修改root密碼
linux mysql修改密碼命令方法1:使用mysqladmin命令
--適用於記得root舊密碼,修改root密碼
語法:
mysqladmin -u用戶名 -p舊密碼 password 新密碼
例如:
# mysqladmin -u root -proot password mysql
--注意:如當舊密碼輸入錯誤時會報如下錯誤
# mysqladmin -u root -proot1 password mysql
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
linux mysql修改密碼命令方法2:直接更新user表password欄位
--適用於忘記root密碼,而對root密碼進行重置
Step 1: 修改MySQL的登錄設置
# vi /etc/my.cnf
--windows系統是my.ini文件
--在[mysqld]的段中加上一句:skip-grant-tables,如沒有[mysqld]欄位,可手動添加上
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
Step 2: 重新啟動mysql
[root@gc ~]# service mysql restart
Shutting down MySQL..[確定]
Starting MySQL...[確定]
Step 3: 登錄並修改MySQL的root密碼
--此時直接用mysql即可無需密碼即可進入資料庫了
[root@gc ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.5.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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> use mysql;
Database changed
mysql> update user set password=password('new_password') where user='root';
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
--注意:如果沒做step1,直接用mysql登錄時會報如下錯誤
[root@gc ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Step 4: 將MySQL的登錄設置修改回來
再刪除/etc/my.cnf文件中的skip-grant-tables
Step 5: 重新啟動mysql
[root@gc ~]# service mysql restart
Shutting down MySQL..[確定]
Starting MySQL...[確定]
2.修改mysql其它用戶密碼
同樣,普通用戶也可以用上面的方法
--使用mysqladmin命令
[root@njdyw ~]# mysqladmin -u user1 -ppass1 password pass2
--直接修改資料庫表
[root@njdyw ~]# mysql -u user1 -ppass1 –Dmysql
mysql> update user set password=password('pass2') where user='user1';
mysql> flush privileges;
⑸ linux中的mysql資料庫密碼忘記了怎麼辦
今天我們主要是講一下關於linux忘記mysql密碼處理方法,下面提供了5種linux忘記mysql密碼找回方法哦。
方法一:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> update user set password=password(newpassword) where user=root;
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
enter password: <輸入新設的密碼newpassword>
mysql>
方法二:
直接使用/etc/mysql/debian.cnf文件中[client]節提供的用戶名和密碼:
# mysql -udebian-sys-maint -p
enter password: <輸入[client]節的密碼>
mysql> update user set password=password(newpassword) where user=root;
mysql> flush privileges;
mysql> quit
# mysql -uroot -p
enter password: <輸入新設的密碼newpassword>
mysql>
方法三:
這種方法我沒有進行過測試,因為我的root用戶默認密碼已經被我修改過了,那位有空測試一下,把結果告訴我,謝謝!!
# mysql -uroot -p
enter password: <輸入/etc/mysql/debian.cnf文件中[client]節提供的密碼>
方法四:
方法如下: 1, 關閉mysql服務 /etc/init.d/mysqld stop 2,使用 –skip-grant-tables選項啟動mysql服務,可以修 改/etc/inin.d/mysqld腳本啟動位置增加此選項, vi /etc/init.d/mysqld
方法如下:
1, 關閉mysql服務
/etc/init.d/mysqld stop
2,使用 –skip-grant-tables選項啟動mysql服務,可以修 改/etc/inin.d/mysqld腳本啟動位置增加此選項,
vi /etc/init.d/mysqld
在下面運行啟動的語句里增加--skip-grant-tables
/usr/bin/mysqld_safe --skip-grant-tables --datadir="$datadir" --socket="$socketfile"
--log-error="$errlogfile" --pid-file="$mypidfile"
加入--skip-grant-tables的意思是啟動mysql服務的時候跳 過許可權表認證。啟動後,連接到mysql的root不需要口令
3,重新啟動mysql服務
/etc/init.d/mysqld start
4. 修改root用戶的密碼;
mysql> update mysql.user set password=password(123456) where user=root;
mysql> flush privileges;
mysql> quit
5. 重新啟動mysql,就可以使用 新密碼登錄了。
mysql
mysql -u root –p
輸入密碼:123456
6,關閉mysql服務
/etc/init.d/mysqld stop
7, 重新修改第2步修改的/etc/init.d/mysqld,使其保持原來不變,也就是取消--skip-grant-tables語句
8,重新 啟動mysql服務
/etc/init.d/mysqld start
⑹ linux下mysql忘記密碼怎麼辦
如果不是root密碼:用root進去,修改mysql資料庫user表咯。
如果是root密碼:
方法一:
MySQL提供跳過訪問控制的命令行參數,通過在命令行以此命令啟動MySQL伺服器:
safe_mysqld --skip-grant-tables&
即可跳過MySQL的訪問控制,任何人都可以在控制台以管理員的身份進入MySQL資料庫。
需要注意的是在修改完密碼以後要把MySQL伺服器停掉重新啟動才會生效
⑺ Linux下MySQL忘記root密碼怎麼辦
1.修改MySQL的配置文件(默認為/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables
2.保存配置文件後,重啟MySQL服務 service mysqld restart
3.再次進入MySQL命令行 mysql -uroot -p,輸入密碼時直接回車,就會進入MySQL資料庫了,這個時候按照常規流程修改root密碼即可。
4.密碼修改完畢後,再按照步驟1中的流程,刪掉配置文件中的那行,並且重啟MySQL服務,新密碼就生效了。
⑻ linux系統mysql忘記root密碼怎麼登錄
如果你有root許可權的話,可以重新修改mysql的密碼步驟如下:
1、修改MySQL的配置文件(默認為/etc/my.cnf),在[mysqld]下添加一行 skip-grant-tables
2、保存配置文件後,重啟MySQL服務 service mysqld restart
3、再次進入MySQL命令行 mysql -u root -p,輸入密碼時直接回車,就會進入MySQL資料庫了,這個時候按照常規流程修改root密碼即可。一般輸入:mysql_secure_installation,然後根據提示輸入新密碼。
密碼修改完畢後,再按照步驟1中的流程,刪掉配置文件中新增加的那行,並且重啟MySQL服務,新密碼就生效了。
⑼ linux下mysql忘記密碼怎麼辦
方法一:
#/etc/init.d/mysqlstop
#mysqld_safe--user=mysql--skip-grant-tables--skip-networking&
#mysql-urootmysql
mysql>updateusersetpassword=password(newpassword)whereuser=root;
mysql>flushprivileges;
mysql>quit
#/etc/init.d/mysqlrestart
#mysql-uroot-p
enterpassword:<輸入新設的密碼newpassword>
mysql>
方法二:
直接使用/etc/mysql/debian.cnf文件中[client]節提供的用戶名和密碼:
# mysql -udebian-sys-maint -p
enter password: <輸入[client]節的密碼>
mysql> update user set password=password(newpassword) where user=root;
mysql> flush privileges;
mysql> quit
# mysql -uroot -p
enter password: <輸入新設的密碼newpassword>
mysql>
⑽ Linux系統下忘記MySql密碼怎麼辦
如果不是root密碼:用root進去,修改mysql資料庫user表咯。
如果是root密碼:
方法一:
MySQL提供跳過訪問控制的命令行參數,通過在命令行以此命令啟動MySQL伺服器:
safe_mysqld --skip-grant-tables&
即可跳過MySQL的訪問控制,任何人都可以在控制台以管理員的身份進入MySQL資料庫。
需要注意的是在修改完密碼以後要把MySQL伺服器停掉重新啟動才會生效
方法二:
可以進行如下的步驟重新設置MySQL的root密碼:
1.首先確認伺服器出於安全的狀態,也就是沒有人能夠任意地連接MySQL資料庫。
因為在重新設置MySQL的root密碼的期間,MySQL資料庫完全出於沒有密碼保護的
狀態下,其他的用戶也可以任意地登錄和修改MySQL的信息。可以採用將MySQL對
外的埠封閉,並且停止Apache以及所有的用戶進程的方法實現伺服器的准安全
狀態。最安全的狀態是到伺服器的Console上面操作,並且拔掉網線。
2.修改MySQL的登錄設置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
保存並且退出vi。
3.重新啟動mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4.登錄並修改MySQL的root密碼
# /usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 『help;』 or 『\h』 for help. Type 『\c』 to clear the buffer.
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 ( 『new-password』 ) WHERE User = 『root』 ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
5.將MySQL的登錄設置修改回來
# vi /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存並且退出vi。
6.重新啟動mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
windows
1.以系統管理員身份登陸系統。
2.打開cmd—–net start 查看mysql是否啟動。啟動的話就停止net stop mysql.
3.我的mysql安裝在d:\usr\local\mysql4\bin下。
4.跳過許可權檢查啟動mysql.
d:\usr\local\mysql4\bin\mysqld-nt –skip-grant-tables
5.重新打開cmd。進到d:\usr\local\mysql4\bin下:
d:\usr\local\mysql4\bin\mysqladmin -uroot flush-privileges password 「newpassword」
d:\usr\local\mysql4\bin\mysqladmin -u root -p shutdown 這句提示你重新輸密碼。
6.在cmd里net start mysql
7.搞定了。
2,MySQL4.1以上版本一種密碼錯誤問題的解決方法
1 # SET PASSWORD FOR 』some_user』@』some_host』 = OLD_PASSWORD(『newpwd』);
2 # FLUSH PRIVILEGES;
3,Mysql資料庫修復
myisamchk -r -q d:\mysql\data\latin1\*
r代表修復
q代錶快速
d:\mysql\data\latin1\*資料庫裡面 *代表裡面的所有的文件
方法三:
如果你忘記了你的MYSQL的root口令的話,你可以通過下面的過程恢復。
1. 向mysqld server 發送kill命令關掉mysqld server(不是 kill -9),存放進程ID的文件通常在MYSQL的資料庫所在的目錄中。
kill `cat /mysql-data-directory/hostname.pid`
你必須是UNIX的root用戶或者是你所運行的SERVER上的同等用戶,才能執行這個操作。
2. 使用`--skip-grant-tables' 參數來啟動 mysqld。
3. 使用`mysql -h hostname mysql'命令登錄到mysqld server ,用grant命令改變口令。你也可以這樣做:`mysqladmin -h hostname -u user password 'new password''。
(其實也可以用use mysql; update user set password =password('yourpass') where user='root' 來做到。)
4. 載入許可權表: `mysqladmin -h hostname flush-privileges' ,或者使用 SQL 命令`FLUSH PRIVILEGES'。(當然,在這里,你也可以重啟mysqld。)
方法四:(一定要先備份)
1,重新在另一台電腦上安裝相同版本的MySQL
2,刪除忘記密碼的電腦中MySQL安裝目錄中\data\mysql的全部內容(要先停止MySQL服務)
3,Copy新裝的電腦上MySQL安裝目錄中\data\mysql的全部內容 to 剛剛刪除的目錄中
4,啟動MySQL服務
這樣就只有一個root用戶了,設置密碼