自己记录一下借鉴的解决办法:
应该是MySQL密码设置的原因
1. sudo cat /etc/mysql/debian.cnf
查看password
2.mysql -u debian-sys-maint -p.........
3.(1) use mysql;
(2) update mysql.user set authentication_string = password('root') where user='root' and Host = 'localhost';
(3) update user set plugin="mysql_native_password";
(4) flush privileges;
(5) Ctrl+d退出
4.sudo service mysql restart;
然后发现在python中可以运行。