【问题标题】:Access denied while running Mysql for the first time on Centos首次在 Centos 上运行 Mysql 时访问被拒绝
【发布时间】:2015-07-31 19:54:29
【问题描述】:

我刚刚使用yum 在 CentOS 机器上第一次安装了 Mysql。安装没有错误。然后我按照以下步骤操作:

$ sudo /sbin/service mysqld start --skip-grant-tables --skip-networking

$ sudo /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 

可以看出,即使在第一次安装后,登录数据库也存在问题。我什至尝试了sudo 中的所有命令,但错误仍然存​​在。我什至不知道如何重新配置​​ MySQL。我也安装了 - 删除了 3 次 mysql。

我该如何解决这个问题?

【问题讨论】:

  • 如果这是你第一次启动mysql,你不应该自己运行它。安全安装脚本应该会为您启动它...
  • 它要求您输入“root”帐户的密码。您需要输入它而不是将其留空
  • 我实际上是按enter 输入密码
  • 是的,错误状态是密码错误。您需要在按 Enter 之前输入它
  • “密码为空”是什么意思?是按回车还是输入某个字符?

标签: mysql centos root


【解决方案1】:

也许你已经在某个时候设置了它。你可以试试这个:

yum remove mysql-server
rm -rf /var/lib/mysql
yum install mysql-server
systemctl start mysqld.service
/usr/bin/mysql_secure_installation

反正我觉得这个问题应该在ServerFault里面。

【讨论】:

  • systemctl 不在我的系统上。我查了一下,这是 Centos 7 的功能。我使用的是 Centos 6。我可以使用/sbin/service mysqld start吗?
  • 然后像以前一样启动服务,但要确保删除 /var/lib/mysql
  • 这完成了工作。 rm -rf /var/lib/mysql 使这成为可能。谢谢!
  • 这是一个矫枉过正,请参阅下面的 SubRed 答案
【解决方案2】:

仅适用于在 MySQL 5.7 上遇到此问题的任何人。或更高。

MySQL v 5.7 或更高版本在安装后生成一个临时随机密码并将其存储在 mysql 错误日志文件中,位于 /var/log/mysqld.log 在 CentOS 7 上通过 MySQL Yum 存储库进行安装。

使用以下命令查看密码:

sudo grep 'temporary password' /var/log/mysqld.log

参考:MySQL 5.7.7 - Centos 7 el7 - Access denied

EDIT1

对于任何有不同错误日志文件的人,您可以使用下面的@Drew 的答案here 找到它。

【讨论】:

  • 靶心!我尝试了费尔南多的解决方案,但它对我不起作用,但这个解决方案做到了!非常感谢! :)
  • 非常感谢!我已经为此苦苦挣扎了几个小时以寻找答案,我什至重新安装了整个操作系统,因为我以为我不小心设置了错误的密码...
  • 谢谢,这个答案应该被接受为合适的答案。
【解决方案3】:
  1. sudo mysql_secure_installation
  2. 当它要求输入密码时输入pass
  3. 按照提示更改root密码

【讨论】:

    【解决方案4】:

    写入错误日志文件的临时 root 密码的视觉效果

    并不是说一个人可以完全摆脱命令

    select @@log_error;
    

    在不登录的情况下查找错误日志文件的位置(先有鸡还是先有蛋的困境)。

    但典型的位置是

    C:\ProgramData\MySQL\MySQL Server 5.7\Data\
    

    (对于 Windows。您必须取消隐藏 C:\ProgramData 目录)

    mysql> select @@log_error;
    +---------------------+
    | @@log_error         |
    +---------------------+
    | /var/log/mysqld.log |
    +---------------------+
    

    (适用于 Linux)

    【讨论】:

      【解决方案5】:

      你误会了。因为你还没有设置密码。你应该只是 不输入。

      为了登录 MariaDB 以保护它,我们需要当前的 root 用户的密码。如果您刚刚安装了 MariaDB,并且 你还没有设置root密码,密码为空, 所以你应该在这里按回车键。

      【讨论】:

        猜你喜欢
        • 2021-10-17
        • 2023-03-20
        • 2017-03-21
        • 2018-07-22
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        • 2014-07-22
        • 1970-01-01
        相关资源
        最近更新 更多