我正在 Ubuntu 12.04 上运行 python 代码,它连接到 Mysql 数据库。创建数据库时,我确保我拥有 super 用户权限。
mysql> SHOW GRANTS FOR 'hammouc'@'localhost';
+--------------------------------------------------------------------------------+
| Grants for hammouc@localhost |
+--------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'hammouc'@'localhost' IDENTIFIED BY PASSWORD <secret> |
| GRANT ALL PRIVILEGES ON `mimclib`.* TO 'hammouc'@'localhost' WITH GRANT OPTION |
+--------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
但是当我在 Ubuntu shell 中运行代码时。我有很多异常(exception),如下所示
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'hammouc'@'localhost' (using password: NO)")
最佳答案
使用mysql,如果用户有密码,则必须提供。不指定密码连接 mysql 的唯一方法是定义一个没有密码的用户(不鼓励这样做)。如果您不想在脚本中指定密码,则必须向用户询问密码,或者从文件中读取密码。
关于python - 使用 python 代码访问 mysql 数据库被拒绝,我对此拥有 super 用户权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36774961/