MySQLdb connection problems

后端 未结 7 1025
逝去的感伤
逝去的感伤 2020-12-30 05:37

I\'m having trouble with the MySQLdb module.

db = MySQLdb.connect(
    host = \'localhost\', 
    user = \'root\', 
    passwd = \'\', 
    db = \'testdb\',          


        
7条回答
  •  说谎
    说谎 (楼主)
    2020-12-30 06:01

    Mysql uses sockets when the host is 'localhost' and tcp/ip when the host is anything else. By default Mysql will listen to both - you can disable either sockets or networking in you my.cnf file (see mysql.com for details).

    In your case forget about the port=3000 the mysql client lib is not paying any attention to it since you are using localhost and specify the socket as in unix_socket='path_to_socket'.

    If you decided to move this script to another machine you will need to change this connect string to use the actual host name or ip address and then you can loose the unix_socket and bring back the port. The default port for mysql is 3306 - you don't need to specify that port but you will need to specify 3000 if that is the port you are using.

提交回复
热议问题