当程序中使用root账号连接mysql时报以下错误,但是使用命令行是可以正常连接的,那么就查询下mysql数据库的user表,查看下当前用户的密码加密方式,看看是不是unix_socket MariaDB [mysql]> select user,plugin from user; +------+-------------+ | user | plugin | +------+-------------+ | root | unix_socket | +------+-------------+ 可以更改下用户的加密方式: update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root';