解决“OperationalError: (1862, 'Your password has expired. To log in you must change it using ...”

来源:互联网 发布:网络与信息安全教程 编辑:程序博客网 时间:2024/05/29 17:42
1. 问题描述
在64位的ubuntu14.10下进行Django框架开发, 在测试mysql是否可以连通时出现以下信息:
xx@ubuntu:~/workspace/day02$ python manage.py shellPython 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2Type "help", "copyright", "credits" or "license" for more information.(InteractiveConsole)>>> from django.db import connection>>> cursor = connection.cursor()Traceback (most recent call last):  File "<console>", line 1, in <module>  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 165, in cursor    cursor = self.make_debug_cursor(self._cursor())  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 138, in _cursor    self.ensure_connection()  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection    self.connect()  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__    six.reraise(dj_exc_type, dj_exc_value, traceback)  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection    self.connect()  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 122, in connect    self.connection = self.get_new_connection(conn_params)  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 472, in get_new_connection    conn = Database.connect(**conn_params)  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/__init__.py", line 81, in Connect    return Connection(*args, **kwargs)  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 187, in __init__    super(Connection, self).__init__(*args, **kwargs2)OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")>>> cursor = connection.cursor()Traceback (most recent call last):  File "<console>", line 1, in <module>  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 165, in cursor    cursor = self.make_debug_cursor(self._cursor())  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 138, in _cursor    self.ensure_connection()  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection    self.connect()  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__    six.reraise(dj_exc_type, dj_exc_value, traceback)  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 133, in ensure_connection    self.connect()  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 122, in connect    self.connection = self.get_new_connection(conn_params)  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 472, in get_new_connection    conn = Database.connect(**conn_params)  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/__init__.py", line 81, in Connect    return Connection(*args, **kwargs)  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 187, in __init__    super(Connection, self).__init__(*args, **kwargs2)OperationalError: (1862, 'Your password has expired. To log in you must change it using a client that supports expired passwords.')>>>
由上面的"OperationalError: (1862, 'Your password has expired. To log in you must change it using a client that supports expired passwords.')"可知, mysql用户的密码过期了
但我记得在安装完mysql后设置了root用户的密码为123456, 且执行以下命令能正常进入mysql的shell:
mysql -uroot -p123456
既然能正常进入mysql的控制台, 但不能正常连接mysql, 那么我们再次设置密码, 我参考了以下链接:http://dev.mysql.com/doc/refman/5.6/en/set-password.html
发现以前那种修改密码的方法不可用, 只有SET PASSWORD = PASSWORD('123456')能有效
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> user mysql;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user mysql' at line 1mysql> use mysql;ERROR 1820 (HY000): You must SET PASSWORD before executing this statementmysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root';ERROR 1046 (3D000): No database selectedmysql> use mysql;ERROR 1820 (HY000): You must SET PASSWORD before executing this statementmysql> SET PASSWORD = PASSWORD('123456');Query OK, 0 rows affected (0.10 sec)mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql>
于是再次测试能否通过连接, 结果成功连上mysql数据库, 如下:
OperationalError: (1862, 'Your password has expired. To log in you must change it using a client that supports expired passwords.')>>> cursor = connection.cursor()>>> 
 
3. 若window下出现这种情况 
若window下出现这种情况, 则到mysql的安装目录下的bin目录下, 执行 mysql -uroot -p 进入mysql shell
OK, Enjoy it!!!
0 0
原创粉丝点击