centos安装mysql后有密码_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

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

在mysql官方文档里找到答案了,原来mysql会为root生成一个默认密码,并且存储在log文件里。通过sudo grep ‘temporary password’ /var/log/mysqld.log可以看到这个密码。

mysql官网文档

刚刚看错了。试试这个

mysql -u root

mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘newpass’);

前几天我也遇到过装了又删,删了又装就是进不去。后来使用源码编译的方法解决了。我装的是mysql5.6

systemctl stop mysql

find / -name my*.cnf

(找到my.cnf文件)

vim /usr/my.cnf

在my.cnf文件的[mysqld]下添加

skip-grant-tables

保存文件

systemctl start mysql

mysql -u root

update mysql.user set password=PASSWORD(‘密码’) where user=’root’;

flush privileges;

exit;

systemctl restart mysql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值