如何重设或更改MySQL root密码? [英] How to reset or change the MySQL root password?

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

问题描述

如何更改ubuntu服务器中的MySQL根密码和用户名?设置任何更改之前,我需要停止mysql服务吗?

How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?

我也有phpmyadmin设置,phpmyadmin会自动更新吗?

I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?

推荐答案

在Ubuntu Linux上设置/更改/重置MySQL根密码.在终端中输入以下行.

Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.

  1. 停止MySQL服务器:sudo /etc/init.d/mysql stop
  2. 启动mysqld配置:sudo mysqld --skip-grant-tables &

  1. Stop the MySQL Server: sudo /etc/init.d/mysql stop
  2. Start the mysqld configuration: sudo mysqld --skip-grant-tables &

在某些情况下,您必须先创建/var/run/mysqld:

In some cases, you've to create the /var/run/mysqld first:

sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld

  • 运行:sudo service mysql start
  • 以root用户身份登录MySQL:mysql -u root mysql
  • 用新密码替换YOURNEWPASSWORD:

  • Run: sudo service mysql start
  • Login to MySQL as root: mysql -u root mysql
  • Replace YOURNEWPASSWORD with your new password:

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

  • 注意:在某些版本中,如果password列不存在,则可能要尝试:
    UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';

    Note: on some versions, if password column doesn't exist, you may want to try:
    UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';

    注意:此方法不被认为是重置密码的最安全方法,但是它可以起作用.

    参考文献:

    1. 在Ubuntu上设置/更改/重置MySQL根密码Linux
    2. 如何重设根密码
    1. Set / Change / Reset the MySQL root password on Ubuntu Linux
    2. How to Reset the Root Password

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

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