解决“OperationalError: (1862, 'Your password has expired. To log in you must change it using ...”
2015-01-05 18:20
1036 查看
1.问题描述
在64位的ubuntu14.10下进行Django框架开发,在测试mysql是否可以连通时出现以下信息:
xx@ubuntu:~/workspace/day02$pythonmanage.pyshell Python2.7.8(default,Oct202014,15:05:19) [GCC4.9.1]onlinux2 Type"help","copyright","credits"or"license"formoreinformation. (InteractiveConsole) >>>fromdjango.dbimportconnection >>>cursor=connection.cursor() Traceback(mostrecentcalllast): File"<console>",line1,in<module> File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line165,incursor cursor=self.make_debug_cursor(self._cursor()) File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line138,in_cursor self.ensure_connection() File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line133,inensure_connection self.connect() File"/usr/local/lib/python2.7/dist-packages/django/db/utils.py",line94,in__exit__ six.reraise(dj_exc_type,dj_exc_value,traceback) File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line133,inensure_connection self.connect() File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line122,inconnect self.connection=self.get_new_connection(conn_params) File"/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py",line472,inget_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",line81,inConnect returnConnection(*args,**kwargs) File"/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/connections.py",line187,in__init__ super(Connection,self).__init__(*args,**kwargs2) OperationalError:(2003,"Can'tconnecttoMySQLserveron'127.0.0.1'(111)") >>>cursor=connection.cursor() Traceback(mostrecentcalllast): File"<console>",line1,in<module> File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line165,incursor cursor=self.make_debug_cursor(self._cursor()) File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line138,in_cursor self.ensure_connection() File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line133,inensure_connection self.connect() File"/usr/local/lib/python2.7/dist-packages/django/db/utils.py",line94,in__exit__ six.reraise(dj_exc_type,dj_exc_value,traceback) File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line133,inensure_connection self.connect() File"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py",line122,inconnect self.connection=self.get_new_connection(conn_params) File"/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py",line472,inget_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",line81,inConnect returnConnection(*args,**kwargs) File"/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/connections.py",line187,in__init__ super(Connection,self).__init__(*args,**kwargs2) OperationalError:(1862,'Yourpasswordhasexpired.Tologinyoumustchangeitusingaclientthatsupportsexpiredpasswords.') >>>
由上面的"OperationalError:(1862,'Yourpasswordhasexpired.Tologinyoumustchangeitusingaclientthatsupportsexpiredpasswords.')"可知,mysql用户的密码过期了
但我记得在安装完mysql后设置了root用户的密码为123456,且执行以下命令能正常进入mysql的shell:
mysql-uroot-p123456
既然能正常进入mysql的控制台,但不能正常连接mysql,那么我们再次设置密码,我参考了以下链接:http://dev.mysql.com/doc/refman/5.6/en/set-password.html
发现以前那种修改密码的方法不可用,只有SETPASSWORD=PASSWORD('123456')能有效:
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>usermysql; ERROR1064(42000):YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'usermysql'atline1 mysql>usemysql; ERROR1820(HY000):YoumustSETPASSWORDbeforeexecutingthisstatement mysql>UPDATEuserSETpassword=PASSWORD('123456')WHEREuser='root'; ERROR1046(3D000):Nodatabaseselected mysql>usemysql; ERROR1820(HY000):YoumustSETPASSWORDbeforeexecutingthisstatement mysql>SETPASSWORD=PASSWORD('123456'); QueryOK,0rowsaffected(0.10sec) mysql>usemysql; Readingtableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql>
于是再次测试能否通过连接,结果成功连上mysql数据库,如下:
OperationalError:(1862,'Yourpasswordhasexpired.Tologinyoumustchangeitusingaclientthatsupportsexpiredpasswords.') >>>cursor=connection.cursor() >>>
3.若window下出现这种情况
若window下出现这种情况,则到mysql的安装目录下的bin目录下,执行mysql-uroot-p进入mysqlshell
OK,Enjoyit!!!
相关文章推荐
- mysql-1862、1820、java.sql.SQLException: Your password has expired. To log in you must change it using a client that supports expired passwords.
- ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supp
- [mysql] ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
- Mysql 5.7 错误号码1862 Your password has expired. To log in you must change it using a client...
- Your password has expired.To log in you must change it using a client that supports expired password
- Your password has expired. To log in you must change it using a client that supports expired passwor
- 【MySQL】MySQL 5.7 "Your password has expired.To log in you must change it using a client that suppor"
- MySQL5.7出现Your password has expired. To log in you must change it using a client that supports expir
- Your password has expired. To log in you must change it using a client that supports expired passwor
- 【完美】Your password has expired. To log in you must change it using a client that supports expired pas
- Your password has expired.To log in you must change it using a client that supports expired password
- Your password has expired.To log in you must change it using a client that supports expired password
- Your password has expired. To log in you must change it using a client that supports expired passwor
- Your password has expired. To log in you must change it using a client that supports expired pass...
- java.sql.SQLException: Your password has expired. To log in you must change it using a client that s
- Your password has expired.To log in you must change it using a client that supports expired password
- Your password has expired. To log in you must change it using a client that supports expired passwords.
- Your password has expired. To log in you must change it using a client that supports expired passwor
- Your password has expired. To log in you must change it using a client that supports expired passwor
- Your password has expired.To log in you must change it using a client that supports expired password