Install MySQLdb under unix

        First, MySQLdb requires a mysql client, make sure mysql_config exists in your environment, which can be installed with yum install mysql-devel, and then make sure mysql_config can be found in the path (view it with find / -name mysql_config ).

  Then download MySQL-python-1.2.4b4, decompress it and enter the main directory to install it, run the following commands: python setup.py build and

python setup.py install, if no error is reported, run python and import MySQLdb to see if an error is reported. If not, the installation goes smoothly.

  During the install process, if you encounter _mysql.c: In function '_mysql_ConnectionObject_Initialize':

_mysql.c:602: error: expected expression before ‘)’ token

error: command 'gcc' failed with exit status 1 , you need to modify the source code of _mysql.c, and find the following code near line 602:

if (!PyArg_ParseTupleAndKeywords(args, kwargs,
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
"|ssssisOiiisssiOii:connect",
#else
"|ssssisOiiisssiOi:connect",
#endif
kwlist,
&host, &user, &passwd, &db,
&port, &unix_socket, &conv,
&connect_timeout,
&compress, &named_pipe,
&init_command, &read_default_file,
&read_default_group,
&client_flag, &ssl,
&local_infile,
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
&read_timeout
#endif
))

  Replace with:

if (!PyArg_ParseTupleAndKeywords(args, kwargs,
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
"|ssssisOiiisssiOii:connect",
#else
"|ssssisOiiisssiOi:connect",
#endif
kwlist,
&host, &user, &passwd, &db,
&port, &unix_socket, &conv,
&connect_timeout,
&compress, &named_pipe,
&init_command, &read_default_file,
&read_default_group,
&client_flag, &ssl,
&local_infile
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
, &read_timeout
#endif
))

  That is, the comma after the fifth-to-last line &local_infile is changed to the beginning of the second-to-last line. Run python setup.py build again and the problem is solved.

  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326941872&siteId=291194637