mysqlroot密碼linux
1、需要root賬號登錄系統,不用登錄mysql;
2、修改/etc/my.cnf,在[mysqld]的段中加:skip-grant-tables
3、重新啟動mysqld:/etc/init.d/mysqld restart
4、現在可以修改MySQLroot密碼 :
/usr/bin/mysql
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,重啟mysql
Ⅱ 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用戶(root)密碼
以下命令適合修改任何 MySQL 用戶,僅以root為例。
首先,你必須要有 操作系統 的root許可權了。也就說需要以root的身份登錄到操作系統,然後進行一下操作。
編輯文件,找到[mysqld],刪除skip-grant-tables這一行
:wq! #保存退出
大功告成!
PS:當然方法不止一種,以上是我比較喜歡用的方法。
Ⅳ Linux下MySQL忘記root密碼怎麼辦
一.MySQL密碼的恢復方法之一
如果忘記了MySQLroot密碼,可以用以下方法重新設置:
1.KILL掉系統里的MySQL進程;
killall-TERMMySQLd
2.用以下命令啟動MySQL,以不檢查許可權的方式啟動;
safe_MySQLd--skip-grant-tables&
3.然後用空密碼方式使用root用戶登錄MySQL;
MySQL-uroot
4.修改MySQLroot用戶的密碼;
1.MySQL>updateMySQL.usersetpassword=PASSWORD('新密碼')whereUser='root';
2.MySQL>flushprivileges;
3.MySQL>quit
重新啟動MySQL,就可以使用新密碼登錄了。
二.MySQL密碼的恢復方法二
有可能你的系統沒有safe_MySQLd程序(比如我現在用的ubuntu操作系統,apt-get安裝的MySQL),下面方法可以恢復
1.停止MySQLd;
sudo/etc/init.d/MySQLstop
(您可能有其它的方法,總之停止MySQLd的運行就可以了)
2.用以下命令啟動MySQL,以不檢查許可權的方式啟動;
MySQLd--skip-grant-tables&
3.然後用空密碼方式使用root用戶登錄MySQL;
1.MySQL-uroot
4.修改MySQLroot用戶的密碼;
1.MySQL>updateMySQL.usersetpassword=PASSWORD('newpassword')whereUser='root';
2.MySQL>flushprivileges;
3.MySQL>quit
重新啟動MySQL
1./etc/init.d/MySQLrestart
就可以使用新密碼newpassword登錄了。
以上的相關內容就是對MySQLroot密碼的解決的介紹,望你能有所收獲。
Ⅳ Linux下MySQL忘記root密碼怎麼辦
一.MySQL密碼的恢復方法之一
如果忘記了MySQL的root密碼,可以用以下方法重新設置:
1.切換到root下
su root
2. KILL掉系統里的MySQL進程;
killall -TERM mysqld
3. 用以下命令啟動MySQL,以不檢查許可權的方式啟動;
safe_mysqld --skip-grant-tables &
4. 然後用空密碼方式使用root用戶登錄 MySQL;
mysql -u root
5. 修改root用戶的密碼;
mysql> update mysql.user set password=PASSWORD('123456') where User='root';
mysql> flush privileges;
mysql> quit
重新啟動MySQL,就可以使用新密碼登錄了。
二. MySQL密碼的恢復方法二
有可能你的系統沒有 safe_mysqld 程序(ubuntu操作系統, apt-get安裝的mysql) , 下面方法可以恢復
1.切換到root下
su root
2. 停止mysqld;
/etc/init.d/mysql stop
3. 用以下命令啟動MySQL,以不檢查許可權的方式啟動;
mysqld --skip-grant-tables &
4. 然後用空密碼方式使用root用戶登錄 MySQL;
mysql -u root
4. 修改root用戶的密碼為123456(當然,你需要將123456改成你要設置的密碼);
mysql> update mysql.user set password=PASSWORD('123456') where User='root';
mysql> flush privileges;
mysql> quit
重新啟動MySQL
/etc/init.d/mysql restart
就可以使用新密碼 123456 登錄了。
Ⅵ Linux下MySQL忘記root密碼怎麼辦
Linux下如果忘記MySQL的root密碼,可以通過修改配置的方法,重置root密碼
修改MySQL的配置文件(默認為/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables
保存配置文件後,重啟MySQL服務 service mysqld restart
再次進入MySQL命令行 mysql -uroot -p,輸入密碼時直接回車,就會進入MySQL資料庫了,這個時候按照常規流程修改root密碼即可。
密碼修改完畢後,再按照步驟1中的流程,刪掉配置文件中的那行,並且重啟MySQL服務,新密碼就生效了。
Ⅶ Linux下MySQL忘記root密碼怎麼辦
關閉mysqld服務 命令:service mysqld stop
修改啟動參數 命令:vim /etc/my.cnf
[mysqld] 下面加入 skip-grant-tables
3.重新啟動mysqld 命令:service mysqld start
4.進入mysql,修改root密碼
5.密碼修改完成後,退出mysql,停止mysqld。
6.修改啟動參數,刪除 skip-grant-tables。
7.再啟動mysqld。
8.已經完成全部操作。
Ⅷ 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忘記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-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 ]
Work for fun,Live for love!