MySQL的root密碼忘記或丟失的解決方法一例
-bash-4.2$ service mysql status
SUCCESS! MySQL running (2670)
-bash-4.2$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
以下是密碼忘記的解決方法:
修改MySQL的引數設定:
# vi /etc/my.cnf
在[mysqld]的段最後一行加上一句:skip-grant-tables
例如:
[mysqld]
........................
log-bin=mysql-bin
innodb_data_file_path = ibdata1:12M;ibdata2:100M;ibdata3:300M:autoextend
innodb_file_per_table=on
max_connections=500
skip-grant-tables --新增加行
儲存並且退出vi.
重啟MySQL服務:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
-bash-4.2$ mysql --不用輸密碼直接登入
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> 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 [mysql]> UPDATE user SET Password = password ('12345678') WHERE User ='root'; --修改為新密碼12345678
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MySQL [mysql]>
MySQL [mysql]> flush privileges; --重新整理一下許可權表
Query OK, 0 rows affected (0.00 sec)
MySQL [mysql]> quit
Bye
將MySQL的引數設定修改回來:
# vi /etc/my.cnf
將剛才在[mysqld]的段中最後一行加上的skip-grant-tables刪除,然後儲存退出。
重啟MySQL服務:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
重新用新密碼登入:
-bash-4.2$ mysql -u root -p12345678 --12345678為新密碼
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 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 [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [mysql]>
SUCCESS! MySQL running (2670)
-bash-4.2$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
以下是密碼忘記的解決方法:
修改MySQL的引數設定:
# vi /etc/my.cnf
在[mysqld]的段最後一行加上一句:skip-grant-tables
例如:
[mysqld]
........................
log-bin=mysql-bin
innodb_data_file_path = ibdata1:12M;ibdata2:100M;ibdata3:300M:autoextend
innodb_file_per_table=on
max_connections=500
skip-grant-tables --新增加行
儲存並且退出vi.
重啟MySQL服務:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
-bash-4.2$ mysql --不用輸密碼直接登入
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> 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 [mysql]> UPDATE user SET Password = password ('12345678') WHERE User ='root'; --修改為新密碼12345678
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MySQL [mysql]>
MySQL [mysql]> flush privileges; --重新整理一下許可權表
Query OK, 0 rows affected (0.00 sec)
MySQL [mysql]> quit
Bye
將MySQL的引數設定修改回來:
# vi /etc/my.cnf
將剛才在[mysqld]的段中最後一行加上的skip-grant-tables刪除,然後儲存退出。
重啟MySQL服務:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
重新用新密碼登入:
-bash-4.2$ mysql -u root -p12345678 --12345678為新密碼
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 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 [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [mysql]>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2124720/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 忘記root密碼的解決方法MySql密碼
- windows下mysql忘記root密碼的解決方法WindowsMySql密碼
- linux忘記mysql root密碼的解決方法LinuxMySql密碼
- mysql丟失root密碼的解決辦法MySql密碼
- SUSE root密碼忘記解決方法密碼
- mysql root密碼丟失MySql密碼
- linux下mysql的root密碼忘記解決LinuxMySql密碼
- MySQL 忘記root密碼解決辦法MySql密碼
- mysql中的root密碼忘記的解決辦法MySql密碼
- mysql誤刪root使用者或者忘記root密碼解決方法MySql密碼
- MySql5.5忘記root密碼的解決辦法MySql密碼
- mysql忘記root密碼MySql密碼
- Linux root密碼丟失的解決辦法Linux密碼
- [Mysql]mysql忘記ROOT密碼MySql密碼
- Mysql忘記密碼解決方法凹MySql密碼
- 解決AIX忘記root密碼的問題AI密碼
- mysql 5.7忘記root密碼MySql密碼
- mysql root 密碼忘記windowsMySql密碼Windows
- Linux平臺MySQL忘記root密碼解決方案LinuxMySql密碼
- CentOS7忘記mysql的root密碼_處理方法.CentOSMySql密碼
- MYSQL修改密碼和忘記ROOT密碼MySql密碼
- MySQL忘記root密碼後的處理MySql密碼
- root密碼丟失後三步解決(轉)密碼
- mysql忘記root密碼恢復MySql密碼
- MySQL 5.7修改忘記root密碼MySql密碼
- [分享] CentOS 6.3忘記root密碼的解決辦法CentOS密碼
- RHEL-6忘記root密碼的解決辦法密碼
- mysql忘記密碼解決方案MySql密碼
- mysql密碼忘記解決方案MySql密碼
- 各類系統ROOT密碼丟失解決辦法密碼
- Linux遺忘root密碼的其中兩種解決方法Linux密碼
- 忘記INTERNAL密碼解決方法密碼
- MySQL_忘記Root密碼並找回MySql密碼
- 關於mysql忘記密碼的解決策略MySql密碼
- solaris11忘記root密碼的處理方法密碼
- MySQL8.0 忘記 root 密碼下如何修改密碼MySql密碼
- Window7下忘記MySQL ROOT密碼MySql密碼
- MySQL5.7忘記root密碼處理MySql密碼