自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在Linux中重置MySQL或者M(jìn)ariaDB的root密碼

系統(tǒng) Linux MariaDB
如果你是第一次設(shè)置 MySQL 或 MariaDB 數(shù)據(jù)庫,你可以直接運(yùn)行 mysql_secure_installation 來實(shí)現(xiàn)基本的安全設(shè)置。其中一項(xiàng)是設(shè)置數(shù)據(jù)庫 root 帳戶的密碼 - 你必須保持私密,并僅在絕對(duì)需要時(shí)使用。如果你忘記了密碼或需要重置密碼,這篇文章會(huì)派上用場(chǎng)。我們將解釋如何在 Linux 中重置或恢復(fù) MySQL 或 MariaDB 的 root 密碼。

[[185729]]

如果你是***次設(shè)置 MySQL 或 MariaDB 數(shù)據(jù)庫,你可以直接運(yùn)行 mysql_secure_installation 來實(shí)現(xiàn)基本的安全設(shè)置。

其中一項(xiàng)是設(shè)置數(shù)據(jù)庫 root 帳戶的密碼 - 你必須保持私密,并僅在絕對(duì)需要時(shí)使用。如果你忘記了密碼或需要重置密碼(例如,當(dāng)數(shù)據(jù)庫管理員換人或被裁員!),這篇文章會(huì)派上用場(chǎng)。我們將解釋如何在 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)境變量:

  1. ------------- SystemD -------------  
  2. # systemctl stop mariadb 
  3. ------------- SysVinit ------------- 
  4. # /etc/init.d/mysqld stop 

接下來,用 --skip-grant-tables 選項(xiàng)啟動(dòng)服務(wù):

  1. ------------- SystemD -------------  
  2. # systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" 
  3. # systemctl start mariadb 
  4. # systemctl status mariadb 
  5. ------------- SysVinit ------------- 
  6. # mysqld_safe --skip-grant-tables &  

 

 

使用 skip tables 啟動(dòng) MySQL/MariaDB 

使用 skip tables 啟動(dòng) MySQL/MariaDB

這可以讓你不用 root 密碼就能連接到數(shù)據(jù)庫(你也許需要切換到另外一個(gè)終端上):

  1. # mysql -u root 

接下來,按照下面列出的步驟來。

  1. MariaDB [(none)]> USE mysql; 
  2. MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourNewPasswordHere'WHERE User='root' AND Host = 'localhost'
  3. MariaDB [(none)]> FLUSH PRIVILEGES

***,停止服務(wù),取消環(huán)境變量設(shè)置并再次啟動(dòng)服務(wù):

  1. ------------- SystemD -------------  
  2. # systemctl stop mariadb 
  3. # systemctl unset-environment MYSQLD_OPTS 
  4. # systemctl start mariadb 
  5. ------------- SysVinit ------------- 
  6. # /etc/init.d/mysql stop 
  7. # /etc/init.d/mysql start 

這可以讓先前的改變生效,允許你使用新的密碼連接到數(shù)據(jù)庫。

總結(jié)

本文我們討論了如何重置 MariaDB/MySQL 的 root 密碼。一如往常,如果你有任何問題或反饋請(qǐng)?jiān)谠u(píng)論欄中給我們留言。我們期待聽到你的聲音。

作者簡(jiǎn)介:

Gabriel Cánepa - 一位來自阿根廷圣路易斯梅塞德斯鎮(zhèn) (Villa Mercedes, San Luis, Argentina) 的 GNU/Linux 系統(tǒng)管理員,Web 開發(fā)者。就職于一家***級(jí)的消費(fèi)品公司,樂于在每天的工作中能使用 FOSS 工具來提高生產(chǎn)力。

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2018-09-08 10:16:18

數(shù)據(jù)庫MySQLMariaDB

2018-12-27 13:35:11

MySQLMySQL 8重置密碼

2020-08-31 07:30:28

UbuntuRoot密碼

2019-09-09 10:25:54

MySQLMariaDB roo密碼

2022-05-26 10:30:48

Fedora操作系統(tǒng)root 密碼

2010-05-12 16:56:44

2015-09-14 14:49:39

MySQLMariaDBLinux

2010-07-19 13:39:01

CentOSroot重置

2024-07-31 16:21:08

2018-05-24 14:40:04

2018-07-31 16:20:12

Windows 10Windows密碼

2020-04-17 08:00:22

Docker命令普通用戶

2010-05-13 18:18:58

MySQL root

2017-04-13 12:20:43

Mysqlroot密碼

2018-05-17 09:15:25

Linux發(fā)行版root密碼

2024-11-25 18:53:55

Linux

2010-02-03 13:50:19

Linux mysql

2017-02-05 17:48:04

Linuxsudo命令密碼會(huì)話

2010-06-09 17:26:54

2010-06-10 15:44:53

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)