Home  >  Q&A  >  body text

[help]centos下安装mysql后,在还未设置密码的情况下无法进入mysql。

1.centos-7.0下安装mysql-5.7
2.此时还没有设置过密码,然后执行mysql命令:mysql -r root
3.提示错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

网上的方法都是先设置密码。

方案一:
mysqladmin -u root password 123456,结果提示错误:error: 'Access denied for user 'root'@'localhost' (using password: NO)'

方案二:
用mysqld_safe skip-grant-tables进入mysql,然后sql语句修改root密码,还是提示错误:-bash: mysqld_safe: command not found

麻烦大家看看这是什么原因。谢谢大家!

天蓬老师天蓬老师2743 days ago687

reply all(4)I'll reply

  • 阿神

    阿神2017-04-17 13:55:53

    I found the answer in the official mysql documentation. It turns out that mysql will generate a default password for root and store it in the log file. You can see this password through sudo grep 'temporary password' /var/log/mysqld.log.

    mysql official website documentation

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:55:53

    I just saw it wrong. Try this
    mysql -u root
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:55:53

    A few days ago, I also encountered the problem of installing and then deleting, and deleting and installing again, but I couldn’t get in. Later, the problem was solved using source code compilation. I installed mysql5.6

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:55:53

    systemctl stop mysql
    find / -name my*.cnf
    (find the my.cnf file)
    vim /usr/my.cnf
    under [mysqld] of the my.cnf file Add
    skip-grant-tables
    Save file
    systemctl start mysql
    mysql -u root
    update mysql.user set password=PASSWORD('password') where user='root';
    flush privileges;
    exit;
    systemctl restart mysql

    reply
    0
  • Cancelreply