MySQL修改root賬號(hào)密碼的方法
MySQL數(shù)據(jù)庫(kù)中如何修改root用戶(hù)的密碼呢?下面總結(jié)了修改root用戶(hù)密碼的一些方法
1: 使用set password語(yǔ)句修改
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.08 sec)
mysql> set password=password('123456');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit

2: 更新mysql數(shù)據(jù)庫(kù)的user表
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('QwE123') where user='root';
Query OK, 4 rows affected (0.03 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit

3:使用mysqladmin命令修改
命令一般為 mysqladmin -u root -p'oldpassword' password newpass 如下所示:
[root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123' Warning: Using a password on the command line interface can be insecure.
驗(yàn)證root密碼修改是否成功
[root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123' Warning: Using a password on the command line interface can be insecure.
上面都是在知道root密碼的情況下修改root密碼,如果忘記了root密碼,如何修改root的密碼呢?
1:首先停掉MySQL服務(wù)
[root@DB-Server ~]# service mysql stop Shutting down MySQL..[ OK ] [root@DB-Server ~]#
或
[root@DB-Server ~]# /etc/rc.d/init.d/mysql stop Shutting down MySQL..[ OK ]
2:然后使用mysqld_safe命令啟動(dòng)mysql,更新root賬號(hào)的密碼
--skip-grant-tables:不啟動(dòng)grant-tables(授權(quán)表),跳過(guò)權(quán)限控制。
--skip-networking :跳過(guò)TCP/IP協(xié)議,只在本機(jī)訪問(wèn)(這個(gè)選項(xiàng)不是必須的??梢圆挥?是可以不用
[root@DB-Server ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 5145
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# 150709 14:10:53 mysqld_safe Logging to '/var/lib/mysql/DB-Server.localdomain.err'.
150709 14:10:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@DB-Server ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql
Database changed
mysql> UPDATE user SET password=PASSWORD("Qwe123") WHERE user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
3:重新啟動(dòng)MySQL服務(wù)。
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡
相關(guān)文章
MYSQL數(shù)據(jù)表?yè)p壞的原因分析和修復(fù)方法小結(jié)(推薦)
MYSQL數(shù)據(jù)表?yè)p壞的原因分析和修復(fù)方法小結(jié),碰到的朋友可以參考,下面整理一些比較全,希望對(duì)大家有所幫助。2011-01-01
使用distinct在mysql中查詢(xún)多條不重復(fù)記錄值的解決辦法
使用distinct在mysql中查詢(xún)多條不重復(fù)記錄值的解決辦法...2006-12-12
實(shí)現(xiàn)mysql級(jí)聯(lián)復(fù)制的方法示例
這篇文章主要介紹了實(shí)現(xiàn)mysql級(jí)聯(lián)復(fù)制的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
MySQL數(shù)據(jù)庫(kù)優(yōu)化與定期數(shù)據(jù)處理策略
在當(dāng)今數(shù)據(jù)驅(qū)動(dòng)的時(shí)代,數(shù)據(jù)庫(kù)作為信息存儲(chǔ)和管理的核心,扮演著至關(guān)重要的角色,本文將探討如何通過(guò)一系列有效的策略來(lái)優(yōu)化 MySQL 數(shù)據(jù)庫(kù)的查詢(xún)效率,并實(shí)現(xiàn)定期處理數(shù)據(jù)的機(jī)制,以確保主表中的數(shù)據(jù)保持在合理范圍內(nèi),需要的朋友可以參考下2025-03-03
MySQL用truncate命令快速清空一個(gè)數(shù)據(jù)庫(kù)中的所有表
這篇文章主要介紹了MySQL用truncate命令快速清空一個(gè)數(shù)據(jù)庫(kù)中的所有表,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
MySL實(shí)現(xiàn)如等級(jí)成色等特殊順序的排序詳解
這篇文章主要為大家介紹了MySL實(shí)現(xiàn)如等級(jí)成色等特殊順序的排序詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
SQL查詢(xún)語(yǔ)句優(yōu)化的實(shí)用方法總結(jié)
下面小編就為大家?guī)?lái)一篇SQL查詢(xún)語(yǔ)句優(yōu)化的實(shí)用方法總結(jié)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12

