如何在 MySQL 中更改/加密 root 密码? [英] How to change/encrypt root password in MySQL?

查看:55
本文介绍了如何在 MySQL 中更改/加密 root 密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MySQL 中有三个用户,分别是 root、testuser1、testuser2.我想在连接到 MySQL 数据库时通过在终端中键入以下命令来加密所有三个用户的密码,

I have three users in MySQL namely root, testuser1, testuser2. I want to encrypt the passwords for all three users when connecting to MySQL database by typing the following command in the terminal,

  1. mysql -u root -p
  2. mysql -u testuser1 -p
  3. mysql -u testuser2 -p

它要求输入密码.此时,我如何提供加密密码或使其从可能包含它的任何文件中读取?

It asks for password. At this point, How can I supply encrypted password or make it read from any file which may contain it?

我的项目要求为 MySQL 用户加密所有密码.(我也问过这个问题与 MariaDB 相关).

There is an requirement in my project to encrypt all passwords for MySQL users. (I have also asked this question in connection with MariaDB too).

推荐答案

你不能在 mysql 客户端命令行上传递一个加密的密码,并期望 mysql 能够理解"它.充其量,您可以将加密的 SSH 会话用于您的 mysql 命令行会话.

You can't pass an encrypted password on the mysql client command line and expect mysql to "understand" it. At best, you can use an encrypted SSH session to for your mysql command line session.

您当然可以将加密的密码存储在文件或数据库中,然后解密它们以进行连接.

You can certainly store encrypted passwords in a file or database, then decrypt them to connect.

但在某些时候,密码必须以明文形式传递给 mySql.您需要准确决定:

But at some point, a password is going to have to be passed to mySql in plaintext. You need to decide exactly:

1) 您将如何登录(从命令提示符?使用程序或网络服务器?

1) how you're going to log on (from a command prompt? Using a program or web server?

2) 如何在登录前和登录期间准确保护存储的密码(包括但不限于加密).

2) How exactly to secure the stored password (including, but not limited to, encryption) up to - and during - logon.

一些替代方案:

MySql 还支持企业登录"方案.也许其中之一可以解决您的问题:

MySql also supports "Enterprise Logon" scenarios. Perhaps one of these might offer a solution to your problem:

可插拔身份验证

最后,如果您从应用程序服务器(例如 WebSphere)使用 MySQL,那么您可以简单地创建一个 DataSource,并让应用程序服务器使用mysql"命令行客户端而不是手动登录为您保护数据库用户名和密码.

Finally, if you're using MySQL from an Application Server (for example, WebSphere), then instead of manually logging in with the "mysql" command line client), you can simply create a DataSource, and let the application server protect the DB username and password for you.

这篇关于如何在 MySQL 中更改/加密 root 密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆