用5.7.30社区版的包装了一个mysql数据库,装好之后mysql -uroot -p进去报错:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using
password: NO)
一开始我以为是权限的问题,然后修改/etc/my.cnf文件,加上skip-grant-tables,变成不用密码认证模式,然后重启数据库,直接mysql -uroot进入数据库,结果发现mysql.user表直接没有数据……于是直接新增用户:
create user ‘root’@‘localhost’ identified by ‘123456’;
提示:
ERROR 1290 (HY000): The MySQL server is running with the
–skip-grant-tables option so it cannot execute this statement mysql> flush privileges;
报错的话,刷新一下权限:
flush privileges;
就可以继续操作了:
create user ‘root’@‘localhost’ identified by ‘123456’;
GRANT ALL PRIVILEGES ON . TO ‘root’@‘localhost’ WITH GRANT OPTION;
flush privileges;
exit;
退出之后,删除配置文件的skip-grant-tables,就可以正常登陆了。