Tuesday, August 18, 2015

Install MySQL Python Connector

[mysql@localhost repo]$ tar zxvf mysql-connector-python-commercial-2.0.4-py2.7.tar.gz
[mysql@localhost repo]$ sudo su -
[root@localhost repo]# cd /mysql/repo/mysql-connector-python-commercial-2.0.4-py2.7
[root@localhost mysql-connector-python-commercial-2.0.4-py2.7]#
[root@localhost mysql-connector-python-commercial-2.0.4-py2.7]# python setup.py install
running install
running build
copying mysql/connector/pooling.pyc -> build/lib/mysql/connector
copying mysql/connector/custom_types.pyc -> build/lib/mysql/connector
copying mysql/connector/fabric/connection.pyc -> build/lib/mysql/connector/fabric
copying mysql/connector/fabric/caching.pyc -> build/lib/mysql/connector/fabric
copying mysql/connector/fabric/balancing.pyc -> build/lib/mysql/connector/fabric
copying mysql/connector/fabric/__init__.pyc -> build/lib/mysql/connector/fabric
copying mysql/connector/catch23.pyc -> build/lib/mysql/connector
copying mysql/connector/connection.pyc -> build/lib/mysql/connector
copying mysql/connector/errorcode.pyc -> build/lib/mysql/connector
copying mysql/connector/cursor.pyc -> build/lib/mysql/connector
copying mysql/connector/conversion.pyc -> build/lib/mysql/connector
copying mysql/connector/authentication.pyc -> build/lib/mysql/connector
copying mysql/connector/locales/eng/client_error.pyc -> build/lib/mysql/connector/locales/eng
copying mysql/connector/locales/eng/__init__.pyc -> build/lib/mysql/connector/locales/eng
copying mysql/connector/locales/__init__.pyc -> build/lib/mysql/connector/locales
copying mysql/connector/errors.pyc -> build/lib/mysql/connector
copying mysql/connector/__init__.pyc -> build/lib/mysql/connector
copying mysql/connector/protocol.pyc -> build/lib/mysql/connector
copying mysql/connector/charsets.pyc -> build/lib/mysql/connector
copying mysql/connector/dbapi.pyc -> build/lib/mysql/connector
copying mysql/connector/utils.pyc -> build/lib/mysql/connector
copying mysql/connector/django/schema.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/introspection.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/client.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/base.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/compiler.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/validation.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/__init__.pyc -> build/lib/mysql/connector/django
copying mysql/connector/django/creation.pyc -> build/lib/mysql/connector/django
copying mysql/connector/constants.pyc -> build/lib/mysql/connector
copying mysql/connector/network.pyc -> build/lib/mysql/connector
copying mysql/connector/optionfiles.pyc -> build/lib/mysql/connector
copying mysql/connector/version.pyc -> build/lib/mysql/connector
copying mysql/__init__.pyc -> build/lib/mysql
running install_lib
running build_py
package init file 'mysql/__init__.py' not found (or not a regular file)
package init file 'mysql/connector/__init__.py' not found (or not a regular file)
package init file 'mysql/connector/locales/__init__.py' not found (or not a regular file)
package init file 'mysql/connector/locales/eng/__init__.py' not found (or not a regular file)
package init file 'mysql/__init__.py' not found (or not a regular file)
package init file 'mysql/connector/__init__.py' not found (or not a regular file)
package init file 'mysql/connector/locales/__init__.py' not found (or not a regular file)
package init file 'mysql/connector/locales/eng/__init__.py' not found (or not a regular file)
running install_egg_info
Removing /usr/lib/python2.7/site-packages/mysql_connector_python-2.0.4-py2.7.egg-info
Writing /usr/lib/python2.7/site-packages/mysql_connector_python-2.0.4-py2.7.egg-info

Sample Python Code for verifying the installation:

import mysql.connector

config = {
  'user': 'root',
  'password': 'complex_password',
  'host': 'localhost',
  'port': '5001',
  'database': 'appdb',
  'raise_on_warnings': True,
}

cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()

query = ("select * from t1")

cursor.execute(query)

for (id,last_updated) in cursor:
  print(str(id)+': '+str(last_updated))

cursor.close()
cnx.close()

[mysql@localhost repo]$ python test.py
1: 2015-08-14 23:01:49
2: 2015-08-14 23:25:42
3: 2015-08-14 23:27:17
4: 2015-08-14 23:29:01
5: 2015-08-14 23:30:00

Setup parameters:

[root@localhost mysql-connector-python-commercial-2.0.4-py2.7]# python setup.py --help
Common commands: (see '--help-commands' for more)

  setup.py build      will build the package underneath 'build/'
  setup.py install    will install the package

Global options:
  --verbose (-v)      run verbosely (default)
  --quiet (-q)        run quietly (turns verbosity off)
  --dry-run (-n)      don't actually do anything
  --help (-h)         show detailed help message
  --no-user-cfg       ignore pydistutils.cfg in your home directory
  --command-packages  list of packages that provide distutils commands

Information display options (just display information, ignore any commands)
  --help-commands     list all available commands
  --name              print package name
  --version (-V)      print package version
  --fullname          print <package name>-<version>
  --author            print the author's name
  --author-email      print the author's email address
  --maintainer        print the maintainer's name
  --maintainer-email  print the maintainer's email address
  --contact           print the maintainer's name if known, else the author's
  --contact-email     print the maintainer's email address if known, else the
                      author's
  --url               print the URL for this package
  --license           print the license of the package
  --licence           alias for --license
  --description       print the package description
  --long-description  print the long package description
  --platforms         print the list of platforms
  --classifiers       print the list of classifiers
  --keywords          print the list of keywords
  --provides          print the list of packages/modules provided
  --requires          print the list of packages/modules required
  --obsoletes         print the list of packages/modules made obsolete

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

No comments:

Post a Comment