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
麻烦大家看看这是什么原因。谢谢大家!
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
I just saw it wrong. Try this
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
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
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