记一次mysql连接错误

mysql_real_connect连接失败

printf("%s\n", mysql_error(&c)); //Access denied for user 'root'@'localhost'
printf("%d", mysql_errno(&c)); //1698

cat /etc/mysql/debian.cnf 先用初始密码登录
USE mysql
select user,plugin from user
发现root的plugin是auth_socket
运行:

update user set authentication_string =password('你的密码'),plugin='msyql_native_password' where user='root';
sudo service mysql stop
sudo service mysql start

解决。

参考:https://www.cnblogs.com/py1612919884/p/9327015.html

posted @ 2022-02-10 20:15  hellozhangjz  阅读(153)  评论(0)    收藏  举报