新聞中心
如果你是第一次設(shè)置 mysql 或 MariaDB 數(shù)據(jù)庫,你可以直接運行 mysql_secure_installation 來實現(xiàn)基本的安全設(shè)置。

在東城等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計、外貿(mào)營銷網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需設(shè)計網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),營銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站制作,東城網(wǎng)站建設(shè)費用合理。
其中一項是設(shè)置數(shù)據(jù)庫 root 帳戶的密碼 - 你必須保持私密,并僅在絕對需要時使用。如果你忘記了密碼或需要重置密碼(例如,當(dāng)數(shù)據(jù)庫管理員換人或被裁員!),這篇文章會派上用場。我們將解釋如何在 linux 中重置或恢復(fù) MySQL 或 MariaDB 的 root 密碼。
建議閱讀: 更改 MySQL 或 MariaDB 的 root 密碼。
雖然我們將在本文中使用 MariaDB,但這些說明同樣也適用于 MySQL。
恢復(fù) MySQL 或者 MariaDB 的 root 密碼
開始之前,先停止數(shù)據(jù)庫服務(wù)并檢查服務(wù)狀態(tài),我們應(yīng)該可以看到先前設(shè)置的環(huán)境變量:
------------- SystemD -------------
# systemctl stop mariadb
------------- SysVinit -------------
# /etc/init.d/mysqld stop
接下來,用 --skip-grant-tables 選項啟動服務(wù):
------------- SystemD -------------
# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
# systemctl start mariadb
# systemctl status mariadb
------------- SysVinit -------------
# mysqld_safe --skip-grant-tables &
使用 skip tables 啟動 MySQL/MariaDB
這可以讓你不用 root 密碼就能連接到數(shù)據(jù)庫(你也許需要切換到另外一個終端上):
# mysql -u root
接下來,按照下面列出的步驟來。
MariaDB [(none)]> USE mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourNewPasswordHere') WHERE User='root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
最后,停止服務(wù),取消環(huán)境變量設(shè)置并再次啟動服務(wù):
------------- SystemD -------------
# systemctl stop mariadb
# systemctl unset-environment MYSQLD_OPTS
# systemctl start mariadb
------------- SysVinit -------------
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
這可以讓先前的改變生效,允許你使用新的密碼連接到數(shù)據(jù)庫。
總結(jié)
本文我們討論了如何重置 MariaDB/MySQL 的 root 密碼。一如往常,如果你有任何問題或反饋請在評論欄中給我們留言。我們期待聽到你的聲音。
Gabriel Cánepa - 一位來自阿根廷圣路易斯梅塞德斯鎮(zhèn) (Villa Mercedes, San Luis, Argentina) 的 GNU/Linux 系統(tǒng)管理員,Web 開發(fā)者。就職于一家世界領(lǐng)先級的消費品公司,樂于在每天的工作中能使用 FOSS 工具來提高生產(chǎn)力。
新聞標(biāo)題:如何在Linux中重置MySQL或者M(jìn)ariaDB的root密碼
文章起源:http://www.dlmjj.cn/article/djecsdc.html


咨詢
建站咨詢
