1 import pymsql
2
3
4 # 创建链接对象
5 conn = pymsql.connect(‘localhost‘, ‘wang‘, ‘123456‘, ‘jingdong‘, ‘utf8‘)
6 # 创建游标
7 cur = conn.cursor()
8 # 执行查询语句
9 cur.execute(‘select * from jingdong;‘)
分析报错内容是在提示我无法连接上MySQL服务器,行,就是说我MySQL服务没开启咯。进到服务里面查看了,MySQL服务的启动情况,是正常开启状态的。其实吧,我也觉得不应该是MySQL服务的问题,因为我客户端现在是可以正常链接MySQL的
1 def __init__(self, host=None, user=None, password="",
2 database=None, port=0, unix_socket=None,
3 charset=‘‘, sql_mode=None,
4 read_default_file=None, conv=None, use_unicode=None,
5 client_flag=0, cursorclass=Cursor, init_command=None,
6 connect_timeout=10, ssl=None, read_default_group=None,
7 compress=None, named_pipe=None,
8 autocommit=False, db=None, passwd=None, local_infile=False,
9 max_allowed_packet=16*1024*1024, defer_connect=False,
10 auth_plugin_map=None, read_timeout=None, write_timeout=None,
11 bind_address=None, binary_prefix=False, program_name=None,
12 server_public_key=None):