mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
translated
This commit is contained in:
parent
ef44d4ba46
commit
3cd20f5274
@ -1,100 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
How To Reset MySQL Or MariaDB Root Password
|
||||
======
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Reset-MySQL-Or-MariaDB-Root-Password-720x340.png)
|
||||
|
||||
Few months ago, I had [**setup LAMP stack in Ubuntu 18.04**][1] server. Today, I tried to login as root user in my database server, but I completely forgot the password. After couple Google searches and going through some blog posts, I successfully reset the password. For those wondering how to do this, this brief tutorial explains how can we reset MySQL or MariaDB Root password in Unix-like operating systems.
|
||||
|
||||
### Reset MySQL or MariaDB Root password
|
||||
|
||||
First, stop the database server.
|
||||
|
||||
If you use MySQL, type the following command and hit ENTER key.
|
||||
```
|
||||
$ sudo systemctl stop mysql
|
||||
|
||||
```
|
||||
|
||||
For MariaDB:
|
||||
```
|
||||
$ sudo systemctl stop mariadb
|
||||
|
||||
```
|
||||
|
||||
Next, restart the database server without permission checking using the following command:
|
||||
```
|
||||
$ sudo mysqld_safe --skip-grant-tables &
|
||||
|
||||
```
|
||||
|
||||
Here, the **`--skip-grant-tables`**option allows you to connect without a password and with all privileges. If you start your server with this option, it also enables `--skip-networking`option which is used to prevent the other clients from connecting to the database server. And, the ampersand **( &)** symbol is used to run the command in background, so you could type the other commands in the following steps. Please be mindful that the above command is dangerous and your database server becomes insecure. You should run this command only for a brief period to reset the password.
|
||||
|
||||
Next, login to your MySQL/MariaDB server as root user:
|
||||
```
|
||||
$ mysql
|
||||
|
||||
```
|
||||
|
||||
At the **mysql >** or **MariaDB [(none)] >** prompt, run the following command to reset the root user password:
|
||||
```
|
||||
UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';
|
||||
|
||||
```
|
||||
|
||||
Replace **NEW-PASSWORD** in the above command with your own password.
|
||||
|
||||
Then, type following commands to exit from the mysql console.
|
||||
```
|
||||
FLUSH PRIVILEGES;
|
||||
|
||||
exit
|
||||
|
||||
```
|
||||
|
||||
Finally, shutdown the running database server that you started earlier with `--skip-grant-tables`option. To do so, run:
|
||||
```
|
||||
$ sudo mysqladmin -u root -p shutdown
|
||||
|
||||
```
|
||||
|
||||
You will be asked to enter your mysql/mariadb root user password that you set in the previous step.
|
||||
|
||||
Now, start mysql/mariadb service normally using command:
|
||||
```
|
||||
$ sudo systemctl start mysql
|
||||
|
||||
```
|
||||
|
||||
For MariaDB:
|
||||
```
|
||||
$ sudo systemctl start mariadb
|
||||
|
||||
```
|
||||
|
||||
Verify if the password has really been changed using the following command:
|
||||
```
|
||||
$ mysql -u root -p
|
||||
|
||||
```
|
||||
|
||||
And, that’s all for today. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-reset-mysql-or-mariadb-root-password/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[1]: https://www.ostechnix.com/install-apache-mariadb-php-lamp-stack-ubuntu-16-04/
|
@ -0,0 +1,98 @@
|
||||
如何重置 MySQL 或 MariaDB 的 Root 密码
|
||||
======
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Reset-MySQL-Or-MariaDB-Root-Password-720x340.png)
|
||||
|
||||
几个月前,我在[**Ubuntu 18.04 上安装了 LAMP**][1]。今天,我尝试以 root 用户身份登录数据库,但我完全忘记了密码。经过一阵 Google 搜索并浏览一些文章后,我成功重置了密码。对于那些想知道如何做到这一点的人,这个简短的教程解释了如何在类 Unix 操作系统中重置 MySQL 或 MariaDB Root 密码。
|
||||
|
||||
### 重置 MySQL 或 MariaDB Root 密码
|
||||
|
||||
首先,停止数据库。
|
||||
|
||||
如果你使用 MySQL,请输入以下命令并下按回车键。
|
||||
```
|
||||
$ sudo systemctl stop mysql
|
||||
|
||||
```
|
||||
|
||||
对于 MariaDB:
|
||||
```
|
||||
$ sudo systemctl stop mariadb
|
||||
|
||||
```
|
||||
|
||||
接下来,使用以下命令在没有权限检查的情况下重新启动数据库:
|
||||
```
|
||||
$ sudo mysqld_safe --skip-grant-tables &
|
||||
|
||||
```
|
||||
|
||||
这里, **`--skip-grant-tables`** 选项让你在没有密码和所有权限的情况下进行连接。如果使用此选项启动服务器,它还会启用 `--skip-networking` 选项,这用于防止其他客户端连接到数据库服务器。并且,**( &)**符号用于在后台运行命令,因此你可以在以下步骤中输入其他命令。请注意,上述命令很危险,并且你的数据库会变得不安全。你应该只在短时间内运行此命令以重置密码。
|
||||
|
||||
接下来,以 root 用户身份登录 MySQL/MariaDB 服务器:
|
||||
```
|
||||
$ mysql
|
||||
|
||||
```
|
||||
|
||||
在 **mysql >** 或 **MariaDB [(none)] >** 提示符下,运行以下命令重置 root 用户密码:
|
||||
```
|
||||
UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';
|
||||
|
||||
```
|
||||
|
||||
使用你自己的密码替换上述命令中的 **NEW-PASSWORD**。
|
||||
|
||||
然后,输入以下命令退出 mysql 控制台。
|
||||
```
|
||||
FLUSH PRIVILEGES;
|
||||
|
||||
exit
|
||||
|
||||
```
|
||||
|
||||
最后,关闭之前使用 `--skip-grant-tables` 选项运行的数据库。为此,运行:
|
||||
```
|
||||
$ sudo mysqladmin -u root -p shutdown
|
||||
|
||||
```
|
||||
|
||||
系统将要求你输入在上一步中设置的 mysql/mariadb 用户密码。
|
||||
|
||||
现在,使用以下命令正常启动 mysql/mariadb 服务:
|
||||
```
|
||||
$ sudo systemctl start mysql
|
||||
|
||||
```
|
||||
|
||||
对于 MariaDB:
|
||||
```
|
||||
$ sudo systemctl start mariadb
|
||||
|
||||
```
|
||||
|
||||
使用以下命令验证密码是否确实已更改:
|
||||
```
|
||||
$ mysql -u root -p
|
||||
|
||||
```
|
||||
|
||||
今天就是这些了。还有更多好东西。敬请期待!
|
||||
|
||||
干杯!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-reset-mysql-or-mariadb-root-password/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[1]: https://www.ostechnix.com/install-apache-mariadb-php-lamp-stack-ubuntu-16-04/
|
Loading…
Reference in New Issue
Block a user