无法登录 MySQL

Rez*_*eza 6 mysql

即使在我使用以下命令重置 root 密码后,我也无法登录 MySQL。(列出的其他命令以提供附加信息。)

    # sudo dpkg-reconfigure mysql-server-5.1

    # mysql -u root -p
    Enter password:
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    # telnet 127.0.0.1 3306
      Trying 127.0.0.1...
      telnet: Unable to connect to remote host: Connection refused
    # ps -Aw |grep mysql
      26522 ?        00:00:00 mysqld

    # /etc/init.d/mysql start
    Rather than invoking init scripts through /etc/init.d, use the service(8)
    utility, e.g. service mysql start

    Since the script you are attempting to invoke has been converted to an
    Upstart job, you may also use the start(8) utility, e.g. start mysql
Run Code Online (Sandbox Code Playgroud)

还,

     # sudo mysqladmin -u root password 123
     mysqladmin: connect to server at 'localhost' failed
Run Code Online (Sandbox Code Playgroud)

看来 MySQL 没有正常运行。

Rin*_*ind 5

每当我需要这样做时,这都有效......

停止 MySQL 服务器:

sudo /etc/init.d/mysql stop
Run Code Online (Sandbox Code Playgroud)

启动mysqld配置。

sudo mysqld --skip-grant-tables &
Run Code Online (Sandbox Code Playgroud)

以 root 身份登录 MySQL。

mysql -u root mysql
Run Code Online (Sandbox Code Playgroud)

用您的新密码替换 YOURNEWPASSWORD!

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
Run Code Online (Sandbox Code Playgroud)