How to Learn: How to Learn Python (2): how to install MySQLdb and how to connect to MySqlEasy_install to install MySQLdb
It's so simple that I don't know what to say. One sentence.
- Sodu easy_install mysql-python
What if an error is reported?
If an error is reported, I can't help it either. I can install it smoothly here, and I can't demonstrate the error even though it works. However, it is said that there are many errors.
You need to believe that you have encountered all the mistakes you have encountered before, so feel free to use the search engine.
Install MySQLdb on Ubuntu
There is no explanation for the same command line.
- Sudo apt-get install python-mysqldb
Install MySQLdb in Windows
In fact, in essence, Windows Installation is complicated. I don't want to do anything about it. I just find a website based on your system. Download the corresponding version. Next step. I can't do anything else.
- Http://www.codegood.com/archives/129
Manually download and install MySQLdb
Compared with other methods, this is a complex and vast project.
First, we must first obtain the source code online!
The downloaded package is a compressed package. What should we do? decompress the package.
Go to the directory and find out where mysql_config is.
Edit site. cfg.
Modify mysql_config to the path found above.
Build
Install:
Do it manually.
Test
The test code is as follows:
- Import MySQLdb
-
- Try:
- Conn = MySQLdb. connect (host = 'localhost', user = 'root', passwd = 'gaopeng', db = 'test', port = 3306)
- Cur = conn. cursor ()
- Cur.exe cute ("select version ()")
- Data = cur. fetchone ()
- Print "Database version: % s" % data
-
-
- Counter t MySQLdb. Error, e:
- Print "Mysql Error % d: % s" % (e. args [0], e. args [1])
-
- Finally:
- If conn:
- Conn. close ()
The test results are as follows: