因为我使用的是win64,所以在此系统下,需要设置为 127.0.0.1

#coding=utf-8

import MySQLdb

if __name__ == '__main__':
# 打开数据库连接
db = MySQLdb.connect("127.0.0.1", "root", "root", "要操作的数据库名") # 使用cursor()方法获取操作游标
cursor = db.cursor() # 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()") # 使用 fetchone() 方法获取一条数据库。
data = cursor.fetchone() print "Database version : %s " % data # 关闭数据库连接
db.close()

运行正常

MySQLdb in Python: “Can't connect to MySQL server on 'localhost'”的更多相关文章

  1. win10,python连接mysql报”Can't connect to MySQL server on 'localhost' (10061)”

    一.环境及问题描述 1. 环境 操作系统:win10家庭版,64bit python版本:Python 2.7.15 mysql版本:mysql 5.4.3 2. 问题描述 最近跟公司申请电脑,预装w ...

  2. 2003-Can't connect to mysql server on localhost (10061)

    mysql数据库出现2003-Can't connect to mysql server on localhost (10061)问题 解决办法:查看wampserver服务器是否启动,如果没有启动启 ...

  3. can't connect to mysql server on 'localhost'(10061)

    在linux下安装Navicat,想说在windows下试一试phpmyadmin之外的mysql图形工具. 显示下载安装了mysql workbench,链接成功.然后又弄了一下输入法重启,想说试一 ...

  4. 解决Can't connect to MySQL server on 'localhost' (10048)

    解决Can't connect to MySQL server on 'localhost' (10048) 您使用的是Windows操作系统,此错误与一个注册表键值TcpTimedWaitDelay ...

  5. MySQL问题记录--Can't connect to MySQL server on localhost (10061)解决方法

    本文mysql的安装环境为win7 64位,mysql版本为MySQL5.7 问题描述:在命令行输入 mysql -u root -p 登录mysql,返回"Can't connect to ...

  6. ruby使用DBI连接MySQL数据库发生异常:in `error': Can't connect to MySQL server on 'localhost' (10061) (DBI::DatabaseError)

    Ruby使用DBI连接MySQL数据库一般为: require "dbi" dbh = DBI.connect("dbi:Mysql:test:localhost&quo ...

  7. mysql中Can't connect to MySQL server on 'localhost' (10061)

    Can't connect to MySQL server on 'localhost' (10061) 第一问题有两个解决方案: 1)没有启动sql服务,以下是具体步骤: 右键-计算机-管理-服务和 ...

  8. 快速解决mysql Lost connection to MySQL server at 'reading initial communication packet及can't connect to mysql server on 'localhost'

    今天在使用Navicat连一个远程mysql时,总是提示连接不成功,提示Lost connection to MySQL server at 'reading initial communicatio ...

  9. ERROR 2003: Can't connect to MySQL server on 'localhost' (10061)

    解决Can't connect to MySQL server on 'localhost'  tomcat连接mysql,大概是c3p0配置和mysql配置都有问题,导致了内存溢出,几天后,mysq ...

随机推荐

  1. bzoj 4712: 洪水

    [权限题][https://www.lydsy.com/JudgeOnline/status.php?problem_id=4712&jresult=4] 这道动态\(dp\)终于不是独立集/ ...

  2. 【转】如何开发自己的HttpServer-NanoHttpd源码解读

    现在作为一个开发人员,http server相关的内容已经是无论如何都要了解的知识了.用curl发一个请求,配置一下apache,部署一个web server对我们来说都不是很难,但要想搞清楚这些背后 ...

  3. php is_callable()与method_exists()函数

    总结就是 method_exists()检查方法是否存在 is_callable()是否存在并可在当前作用域是否可调用

  4. angularjs ng-if ng-show ng-hide区别

    在使用anularjs开发前端页面时,常常使用ng-show.ng-hide.ng-if功能来控制页面元素的显示或隐藏,那他们之间有什么不同呢? 实现原理方面:ng-show/ng-hide是通过修改 ...

  5. Ubuntu 编译出现 ISO C++ 2011 不支持的解决办法

    问题 在编译时出现如下error: error:This file requires compiler and library support for the ISO C++ 2011 standar ...

  6. VPP(Vector Packet Processing)配置工具

    前言 VPP提供了一个配置工具,让用户可以简单快捷地配置VPP.用户可以通过一些简单的命令配置VPP,功能包括安装及一些基本配置和测试用例. 使用 先安装一个python的pip模块,使用pip安装V ...

  7. HTTPweb服务器——HTTP基本知识

    对于HTTP来说,我们不需要说太多,HTTP又叫做超文本传输协议,现如今利用最多的版本是1.1版本. HTTP的特点:C/S模式,B/S模式 简单快速:基于请求和响应,请求只需要传送请求方法和路径.  ...

  8. 进程通信-Queue

    进程通信-Queue Queue消息队列是python进程通信的其中一种方式.需要引入multiprocessing包中的Queue函数(这是函数,不是类). 有一个queue包,里面也有Queue, ...

  9. tomcat启动超时, Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds...

    本文转自于:http://www.cnblogs.com/yjhrem/articles/2955207.html

  10. MySQL学习【第七篇索引管理及执行计划】

    一.索引介绍 1.什么是索引? 索引由如字典,目的就是为了更快寻找到要找的内容. 令搜索查询的数据更有目的性,从而提高数据检索的能力 2.索引类型介绍 1.BTREE: B+树索引 2.HASH: H ...