在ubunt下使用sudo apt-get install mysql
命令直接安装mysql,访问时会报以下错误
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
解决办法:
1.使用安全模式进入mysql
在/etc/mysql/mysql.conf.d/mysqld.cnf文件下的[mysqld]字段下加入一行“skip-grant-tables”
2.重启mysql服务
sudo systemctl restart mysql
3.使用安全模式进入mysql并修改root密码
mysql
use mysql
#把密码重置为123456
update user set authentication_string=password('123456') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;#刷新系统权限相关表
quit#退出mysql
4.将第一步文件中的skip-grant-tables注释掉,并重启MySQL服务器。
sudo systemctl restart mysql