markdown 如何通过命令行在Linux或macOS中更改MySQL root密码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何通过命令行在Linux或macOS中更改MySQL root密码相关的知识,希望对你有一定的参考价值。

If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset the mysql database password from the command line in either Linux or macOS Sierra and OSX as long as you know the root user password of the box you are on, this is for MySQL 5.7 onwards:

Stop MySQL
```
sudo /usr/local/mysql/support-files/mysql.server stop
```

Start it in safe mode:
```
sudo mysqld_safe --skip-grant-tables
```

This will be an ongoing command until the process is finished so open another shell/terminal window, and log in without a password as root:
```
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
```
Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.

```
\q
```

Start MySQL
```
sudo /usr/local/mysql/support-files/mysql.server start
```
Thats it, now your root password will be updated.

以上是关于markdown 如何通过命令行在Linux或macOS中更改MySQL root密码的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 mvn -D 通过命令行在 Maven 中设置(多个)属性?

如何通过命令行在 MSBuild 中指定 CodeAnalysisRuleset

如何通过命令行在pytest中传递参数

如何通过命令行在 GitHub 上发布版本?

如何通过命令行在本地更新存储库[复制]

如何使用 CMAKE 从命令行在 Windows 上构建 x86 和/或 x64?