如何更改 MySQL 的 USERNAME 和 PASSWORD?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20562648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:40:05  来源:igfitidea点击:

How to change USERNAME And PASSWORD of MySQL?

mysql

提问by Dnyanesh M

I have installed MySQL Server 5.0on my machine (Windows-7 OS).

我已经在我的机器(Windows-7 操作系统)上安装了MySQL Server 5.0

My existing USERNAME And PASSWORD for MySQL is root, root and now due to some reason I wants to change both USERNAME And PASSWORD also.

我现有的 MySQL USERNAME 和 PASSWORD 是 root,root,现在由于某种原因我想同时更改 USERNAME 和 PASSWORD。

Many people have asked this question before but no one I found useful for me. So can anybody please tell me HOW and from WHEREcan I change it?

以前有很多人问过这个问题,但没有一个我觉得对我有用。所以有人可以告诉我如何以及从哪里可以更改它?

回答by Ghigo

Just execute this query from mysql console:

只需从 mysql 控制台执行此查询:

 UPDATE mysql.user SET user='newusername',
 password=PASSWORD('newpassword') WHERE user='root';
 FLUSH PRIVILEGES;

回答by Amarnath Balasubramanian

Instructions

指示

  1. Click the Windows "Start" button and type "cmd" in the search text box. Press Enterto open the Windows command line.

  2. Type "mysql" and press Enterto start the MySQL command line utility. Using the MySQL command line, you can update the tables on the database.

  3. Type the following SQL code to update the root user:
    UPDATE mysql.user SET user='newuser' WHERE User = 'root';
    Change newuserwith the value you want to use in place of root

  4. Type the following SQL code to change the default user's password:
    UPDATE mysql.user SET authentication_string = password('pass') WHERE User = 'newuser';
    Replace passwith the new password, and replace newuserwith the name of the user you set up in the previous step.

  1. 单击 Windows“开始”按钮并在搜索文本框中键入“cmd”。按Enter打开 Windows 命令行。

  2. 键入“mysql”并按下Enter以启动 MySQL 命令行实用程序。使用 MySQL 命令行,您可以更新数据库上的表。

  3. 键入以下 SQL 代码以更新 root 用户:使用要代替的值
    UPDATE mysql.user SET user='newuser' WHERE User = 'root';
    更改newuserroot

  4. 键入以下 SQL 代码以更改默认用户的密码:
    UPDATE mysql.user SET authentication_string = password('pass') WHERE User = 'newuser';
    替换pass为新密码,并替换newuser为您在上一步中设置的用户名。

Read more

阅读更多

To change UserName and Password from mysql console

从 mysql 控制台更改用户名和密码

回答by Nambi

USE THIS CMD IN MYSQL CONSOLE OR CMD

在 MYSQL 控制台或 CMD 中使用此 CMD

STEP1: mysql> use mysql;

1mysql> use mysql;

STEP2: CREATE USER 'username'@'localhost' IDENTIFIED BY 'mypass';

2CREATE USER 'username'@'localhost' IDENTIFIED BY 'mypass';

回答by foobar

I'll suggest to stay with a root user and change the password if you want. Having a root user is convenient and renaming it is debatable (see this conversation). Plus, calling it 'root' is not that "unsecured" if you respect good practices (such as IP/hostname restriction).

如果需要,我建议继续使用 root 用户并更改密码。拥有 root 用户很方便,重命名它是有争议的(请参阅此对话)。另外,如果您尊重良好做法(例如 IP/主机名限制),则称其为“root”并不是那么“不安全”。

Conclusion : change the root password and secure access to your server if you still feel unconfortable. Then, create another user with USERNAME as the login and PASSWORD as the password.

结论:如果您仍然感到不舒服,请更改 root 密码并安全访问您的服务器。然后,使用 USERNAME 作为登录名和 PASSWORD 作为密码创建另一个用户。

  1. To change the root password (in a MySQL Console) :

    UPDATE mysql.user SET Password=PASSWORD('YOURPASSWORDHERE') WHERE User='root'; FLUSH PRIVILEGES;

  2. To create a new user : http://dev.mysql.com/doc/refman/5.0/fr/create-user.html

  3. If your root user has a lot of privileges you don't want to replicate manually to the newly created user, then using a stored procedure could be a good solution : Copy user privileges between databases on the same server

  1. 要更改 root 密码(在 MySQL 控制台中):

    更新 mysql.user SET Password=PASSWORD('YOURPASSWORDHERE') WHERE User='root'; 同花顺特权;

  2. 创建一个新用户:http: //dev.mysql.com/doc/refman/5.0/fr/create-user.html

  3. 如果您的 root 用户拥有很多权限,您不想手动复制到新创建的用户,那么使用存储过程可能是一个不错的解决方案:在同一服务器上的数据库之间复制用户权限

回答by Devart

There are special MySQL commands:

有特殊的 MySQL 命令:

  1. RENAME USER
  2. SET PASSWORD
  1. 重命名用户
  2. 设置密码

回答by Mad Dog Tannen

I not sure if you can change the username, you could drop it and create antoher one instead but not sure if update is possible.

我不确定您是否可以更改用户名,您可以删除它并创建另一个用户名,但不确定是否可以更新。

Login to the commandline promt.

登录到命令行提示符。

Set the mysql database

设置mysql数据库

USE mysql;

Create the new user first if rootis your only username

如果root是您唯一的用户名,则首先创建新用户

CREATE USER 'newusername'@'localhost' IDENTIFIED BY 'newpass';

Then drop the old root

然后删除旧根

DROP user root;

http://dev.mysql.com/doc/refman/5.0/en/user-names.html

http://dev.mysql.com/doc/refman/5.0/en/user-names.html

http://dev.mysql.com/doc/refman/5.0/en/create-user.html

http://dev.mysql.com/doc/refman/5.0/en/create-user.html