在Ubuntu安装好MySQL后报错
安装命令(Ubuntu 20.04):
sudo apt install mysql-serversudo systemctl start mysql.servicesudo mysql_secure_installation
然后查看版本会报错
➜ ~ mysql -vERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)➜ ~ mysql --versionmysql Ver 8.0.29-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
原因为用户设置有问题
通过sudo mysql进入
sudo mysql
然后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
重新登录可以了
mysql -u root -p