python下连接mysql的错误 错误码 【10061】

<span style="font-size:18px;"># encoding: utf-8
#!/usr/bin/python

import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("localhost","root","123456","test" )</span>

显示错误:

OperationalError: (2003, "Can‘t connect to MySQL server on ‘localhost‘ (10061)")

错误原因:

原来错误出现在localhost这个名称的解析上。

修改方法:修改为iP,若为本地测试,修改为127.0.0.1;若为服务器:修改为IP。

# encoding: utf-8
#!/usr/bin/python

import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("127.0.0.1","root","123456","test" )
时间: 2024-08-29 09:37:27

python下连接mysql的错误 错误码 【10061】的相关文章

Ubuntu下连接mysql出现 ERROR 1698 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39;错误解决方法

ubuntu版本:18.04    mysql版本:5.7.24 ubuntu安装mysql后用root账户登入会出现问题:ERROR 1698 (28000): Access denied for user 'root'@'localhost' 可能是因为初始密码为空:按空格回车后还是报一样的错 这样就只能使用debian-sys-maint账户修改root账户密码了. debian-sys-maint账户是安装mysql时系统自动生成的mysql用户,debian和ubuntu系统都会这样做

IDEA连接mysql又报错!Server returns invalid timezone. Go to &#39;Advanced&#39; tab and set &#39;serverTimezone&#39; prope

错误界面 IDEA连接mysql,地址,用户名,密码,数据库名,全都配置好了,点测试连接,咔!不成功! 界面是这样的, 翻译过来就是:服务器返回无效时区.进入“高级”选项卡,手动设置“serverTimezone”属性. 看起来是时区出了问题.时区怎么会出问题?坑真多.网上搜了各种解决办法,琳琅满目,复杂的简单的,总算是解决了! 解决方案我的问题出在两块,第一,设置mysql的时区.第二,mysql驱动的版本.详细步骤如下: 第一,设置mysql时区.1,我们先来检查下mysql时区. 配置完环

【问题解决】连接mysql 8错误:authentication plugin &#39;caching_sha2_password

在刚安装好mysql8,使用native连接的时候报错 authentication plugin 'caching_sha2_password'... 首先确保服务已开启,然后通过cmd命令进入mysql的localhost数据库 mysql -hlocalhost -uroot -p123456 然后进入mysql数据库 use mysql; 修改密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY

python下操作mysql 之 pymsql

python下操作mysql  之  pymsql pymsql是Python中操作MySQL的模块, 下载安装: pip3 install pymysql 使用操作 1, 执行SQL #!/usr/bin/env python # -*- coding:utf-8 -*- import pymysql # 创建连接 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='t1') #

关于springboot 连接mysql 数据库报错问题

springboot连接MySQL运行报错: The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zon

java连接MySQL运行报错The server time zone value &#39;&#214;&#208;&#185;&#250;&#177;&#234;&#215;&#188;&#202;&#177;&#188;&#228;&#39; is unrecognized or represents more than

错误:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than 原因:time zone 时区错误 解决方法: 1.使用root用户登录mysql,输入下面命令. show variables like '%time_zone%';SYSTEM为SQL默认美国时间,而我们中国要比他们迟8小时 2.SYSTEM为SQL默认美国时间,而我们中国要比他们迟8小时,因此将时区设置为当前系统时区即可,

Navicat 连接MySQL数据库 报错2059 - authentication plugin &#39;caching_sha2_password&#39;的解决办法

#在数据库的命令行中输入以下代码即可解决,密码必须要修改 可以再次执行将密码改回来. use mysql; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; Navicat 连接MySQL数据库 报错2059 - authentication plugin 'caching_sha2_password'的解决办法 原文地址:https://www.cnblogs.com/liuha

python在windows下连接mysql数据库

一,安装MySQL-python python 连接mysql数据库需要 Python interface to Mysql包,包名为 MySQL-python ,PyPI上现在到了1.2.5版本.MySQL-python在windows下是通过.exe文件的installer安装的, 前提是已经安装的python需要写入注册表,参考这篇文章:windows安装python2.7后的注册(registry)问题. 然后开始安装MySQL-python,不过这里有个坑,从PyPI上下载的MySQL

python MySQLdb连接mysql时报错

故障现象: >>> import MySQLdb >>> conn = MySQLdb.connect(host="localhost",user="root",passwd="tiange1003",db="tian",port=3306,charset="utf8") Traceback (most recent call last): File "<