国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL修改root賬號密碼的方法

2024-07-24 13:07:43
字體:
來源:轉載
供稿:網友

這篇文章介紹了兩種情況,知道root密碼的情況下修改root密碼,以及忘記了root密碼,如何對root的密碼進行修改,需要的朋友可以參考下

MySQL數據庫中如何修改root用戶的密碼呢?下面總結了修改root用戶密碼的一些方法

1: 使用set password語句修改

 

 
  1. mysql> select user(); 
  2. +----------------+ 
  3. | user() | 
  4. +----------------+ 
  5. | root@localhost | 
  6. +----------------+ 
  7. 1 row in set (0.08 sec) 
  8.  
  9. mysql> set password=password('123456'); 
  10. Query OK, 0 rows affected (0.00 sec) 
  11.  
  12. mysql> flush privileges; 
  13. Query OK, 0 rows affected (0.00 sec) 
  14.  
  15. mysql> exit 

MySQL修改root賬號密碼的方法

2: 更新mysql數據庫的user表

 

 
  1. mysql> use mysql; 
  2. Reading table information for completion of table and column names 
  3. You can turn off this feature to get a quicker startup with -A 
  4.  
  5. Database changed 
  6. mysql> update user set password=PASSWORD('QwE123') where user='root'
  7. Query OK, 4 rows affected (0.03 sec) 
  8. Rows matched: 4 Changed: 4 Warnings: 0 
  9.  
  10. mysql> flush privileges; 
  11. Query OK, 0 rows affected (0.00 sec) 
  12.  
  13. mysql> quit 

MySQL修改root賬號密碼的方法

3:使用mysqladmin命令修改

命令一般為 mysqladmin -u root -p'oldpassword' password newpass 如下所示:

 

 
  1. [root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123' 
  2. Warning: Using a password on the command line interface can be insecure. 

驗證root密碼修改是否成功

 

 
  1. [root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123' 
  2. Warning: Using a password on the command line interface can be insecure. 

上面都是在知道root密碼的情況下修改root密碼,如果忘記了root密碼,如何修改root的密碼呢?

1:首先停掉MySQL服務

 

 
  1. [root@DB-Server ~]# service mysql stop 
  2. Shutting down MySQL..[ OK ] 
  3. [root@DB-Server ~]# 

 

 
  1. [root@DB-Server ~]# /etc/rc.d/init.d/mysql stop 
  2. Shutting down MySQL..[ OK ] 

2:然后使用mysqld_safe命令啟動mysql,更新root賬號的密碼

--skip-grant-tables:不啟動grant-tables(授權表),跳過權限控制。

--skip-networking :跳過TCP/IP協議,只在本機訪問(這個選項不是必須的。可以不用)是可以不用

 

 
  1. [root@DB-Server ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
  2. [1] 5145 
  3. You have new mail in /var/spool/mail/root 
  4. [root@DB-Server ~]# 150709 14:10:53 mysqld_safe Logging to '/var/lib/mysql/DB-Server.localdomain.err'
  5. 150709 14:10:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 
  6.  
  7. [root@DB-Server ~]# mysql -u root mysql 
  8. Reading table information for completion of table and column names 
  9. You can turn off this feature to get a quicker startup with -A 
  10.  
  11. Welcome to the MySQL monitor. Commands end with ; or /g. 
  12. Your MySQL connection id is 1 
  13. Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial) 
  14.  
  15. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 
  16.  
  17. Oracle is a registered trademark of Oracle Corporation and/or its 
  18. affiliates. Other names may be trademarks of their respective 
  19. owners. 
  20.  
  21. Type 'help;' or '/h' for help. Type '/c' to clear the current input statement. 
  22.  
  23. mysql> show databases; 
  24. +--------------------+ 
  25. | Database | 
  26. +--------------------+ 
  27. | information_schema | 
  28. | mysql | 
  29. | performance_schema | 
  30. | test | 
  31. +--------------------+ 
  32. 4 rows in set (0.00 sec) 
  33.  
  34. mysql> use mysql 
  35. Database changed 
  36. mysql> UPDATE user SET password=PASSWORD("Qwe123") WHERE user='root';  
  37. Query OK, 4 rows affected (0.01 sec) 
  38. Rows matched: 4 Changed: 4 Warnings: 0 
  39.  
  40. mysql> flush privileges; 
  41. Query OK, 0 rows affected (0.00 sec) 
  42.  
  43. mysql> exit 
  44. Bye 

3:重新啟動MySQL服務。

以上所述就是本文的全部內容了,希望大家能夠喜歡

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汶川县| 大港区| 彭阳县| 萝北县| 临洮县| 宜兰市| 叙永县| 红河县| 合肥市| 阿勒泰市| 桂东县| 元阳县| 托里县| 广西| 宜兰市| 寻乌县| 虹口区| 民丰县| 郸城县| 北宁市| 阿克苏市| 林周县| 土默特右旗| 新津县| 河间市| 西昌市| 时尚| 平阳县| 金门县| 清远市| 南江县| 常宁市| 襄樊市| 公安县| 曲阜市| 牡丹江市| 贵阳市| 邮箱| 长宁区| 邯郸县| 五家渠市|