代码之家  ›  专栏  ›  技术社区  ›  Stormshadow

如何将根密码设置为空

  •  56
  • Stormshadow  · 技术社区  · 16 年前

    如何更改的密码 root MySQL用户 null --表示没有密码或 '' --从mysql命令行客户端?

    18 回复  |  直到 7 年前
        1
  •  13
  •   Alex    8 年前

    您可以通过以下五个简单步骤恢复MySQL数据库服务器密码。

    第1步 :停止mysql服务器进程。

    第2步 :使用--skip grant tables选项启动mysql(mysqld)服务器/守护进程,这样它就不会提示输入密码。

    第3步 :以根用户身份连接到mysql服务器。

    第4步 :设置新的mysql根帐户密码,即重置mysql密码。

    第5步 :退出并重新启动MySQL服务器。

    以下是您需要为每个步骤键入的命令(以根用户身份登录):

    第1步 :停止MySQL服务

    # /etc/init.d/mysql stop
    

    输出:

    Stopping MySQL database server: mysqld.
    

    第2步 :无密码启动MySQL服务器:

    # mysqld_safe --skip-grant-tables &
    

    输出:

    [1] 5988
    Starting mysqld daemon with databases from /var/lib/mysql
    mysqld_safe[6025]: started
    

    第3步 :使用mysql客户端连接到mysql服务器:

    # mysql -u root
    

    输出:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    mysql>
    

    第4步 :设置新的mysql根用户密码

    mysql> use mysql;
    mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    mysql> flush privileges;
    mysql> quit
    

    步骤5 :停止MySQL服务器:

    #/etc/init.d/mysql停止
    

    输出:

    Stopping MySQL database server: mysqld
    STOPPING server from pid file /var/run/mysqld/mysqld.pid
    mysqld_safe[6186]: ended
    [1]+  Done                    mysqld_safe --skip-grant-tables
    

    第6步 :启动mysql服务器并测试

    # /etc/init.d/mysql start
    # mysql      
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 
    # mysql -u root -p
    

    来源: http://www.cyberciti.biz/tips/recover-mysql-root-password.html

        2
  •  66
  •   Stanislav Karakhanov    10 年前

    为我和“5.7.11 mysql社区服务器”工作:

    use mysql;
    update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
    

    我还必须更改“plugin”字段,因为它被设置为“auth_socket”。

    之后我可以连接 mysql -u root 没有密码。

        3
  •  52
  •   user64141    14 年前

    如果需要空密码,则应将密码设置为空,而不使用密码哈希函数,例如:

    在命令行上:

    sudo service mysql stop
    sudo mysqld_safe --skip-grant-tables --skip-networking &
    mysql -uroot
    

    在MySQL中:

    use mysql;
    update user set password=null where User='root';
    flush privileges;
    quit;
    
        4
  •  50
  •   eigenein    12 年前
    • 作为用户根目录连接到MySQL(使用以下两种方法之一)
      • 以root身份登录并使用 mysql -p ,输入当前根密码
      • 以自我身份登录并使用 mysql -u root -p ,输入当前根密码
    • mysql> set password = password('');

    完成!没有根密码。

        5
  •  19
  •   4b0 Agit    8 年前
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
    
        6
  •  13
  •   djordjea    9 年前

    这在Ubuntu 16.04和v5.7.15 MySQL上对我很有用:

    首先,确保安装了MySQL客户端( sudo apt-get install mysql-client )

    打开终端并登录:

    mysql -uroot -p
    

    (然后键入密码)

    之后:

    use mysql;
    update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
    

    (TNX@Stanislav Karakhanov)

    最重要的是 重置MySQL服务 以下内容:

    sudo service mysql restart
    

    现在,您还可以使用mysql工作台登录(不使用passsword)。

        7
  •  4
  •   Gustavo Straube    8 年前

    编辑不是个好主意 mysql 直接数据库。

    我喜欢以下步骤:

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ''; 
    mysql> flush privileges;
    
        8
  •  4
  •   Nicolas Rivas    8 年前

    对于MySQL8.0,只需:

    SET PASSWORD FOR 'root'@'localhost' = '';

        9
  •  1
  •   user3430227    11 年前

    用户回答64141

    use mysql;
    update user set password=null where User='root';
    flush privileges;
    quit;
    

    在Mariadb10.1.5中不适合我(应该是MySQL的替代品)。虽然没有在MySQL5.6中测试它来查看是否是上游更改,但我得到的错误是:

    错误1048(23000):“密码”列不能为空

    但是用空的单引号或双引号替换空值可以很好地工作。

    update user set password='' where User='root';
    

    update user set password="" where User='root';
    
        10
  •  1
  •   user9903233    8 年前

    它对我有用。

    将用户'root'@'localhost'通过'password'更改为mysql_native_password

        11
  •  0
  •   Hamid Faisal    10 年前

    如果您知道您的根密码,只想重置它,请按以下步骤操作:

    • 从控制面板>管理工具>服务启动MySQL服务。(前提是你早点阻止了它!否则,跳过此步骤)

    • 启动MySQL工作台

    • 键入此命令/sql行

      更改用户'root'@'localhost'密码过期;

    要重置任何其他用户密码…只需键入其他用户名而不是根。

        12
  •  0
  •   Tom DE RUDDER    8 年前

    无密码连接mysql:

    mysql -p SET PASSWORD = ""

    https://dev.mysql.com/doc/refman/5.7/en/set-password.html

        13
  •  0
  •   Kaushik    8 年前

    我正在使用nodejs和windows 10。两个答案的结合对我很有用。

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ''; 
    mysql> flush privileges;
    

    然后:

    restart;
    

    希望这对其他仍有问题的人有所帮助。

        14
  •  0
  •   nofunatall    8 年前

    根据版本的不同,语法略有不同。从这里的文档: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

    MySQL5.7.6及更高版本:

    ALTER USER 'root'@'localhost' IDENTIFIED BY '';
    

    MySQL5.7.5及更早版本:

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
    
        15
  •  0
  •   MrSmile cashews    8 年前

    我的mysql 5.7变体:

    停止服务mysql:

    $ sudo service mysql stop
    

    在安全模式下运行:

    $ sudo mysqld_safe --skip-grant-tables --skip-networking
    

    (上面一行是整个命令)

    打开新的终端窗口:

    $ mysql -u root
    
    $ mysql use mysql;
    
    $ mysql update user set authentication_string=password('password') where user='root';
    
    $ mysql update user set plugin="mysql_native_password" where User='root';
    
    $ mysql flush privileges;
    $ mysql quit;
    

    运行mysql服务:

    $ sudo service mysql start
    
        16
  •  0
  •   Tyler Moore    7 年前

    想把我自己的东西放在这里,但是上面的答案对我不起作用。 在Centos7上,mysql社区v8,shell是bash。

    正确的命令如下:

    # start mysql without password checking
    systemctl stop mysqld 2>/dev/null
    systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" &&
    systemctl start mysqld
    
    # set default password to nothing
    mysql -u root mysql <<- 'EOF'
        FLUSH PRIVILEGES;
        UNINSTALL COMPONENT 'file://component_validate_password';
        ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
        FLUSH PRIVILEGES;
        INSTALL COMPONENT 'file://component_validate_password';
    EOF
    
    # restart mysql normally
    systemctl restart mysqld
    

    然后您可以不用密码登录:

    mysql -u root
    
        17
  •  0
  •   Vinayak Shedgeri    7 年前

    这都是因为你安装了比5.6更高版本的MySQL

    解决

    1.可以降级mysql版本解决方案

    2使用
    配置选项

        18
  •  0
  •   Shuai Li    7 年前

    这是来自MySQL8.0.13的:

    use mysql;
    
    update user set authentication_string=null  where user='root';
    
    quit;
    
    推荐文章