Python compared to the fire recently, I think Python this language speed is not fast, do project also general, learn what he do? But learned that Python has other language functions encapsulated into its own package, with Python can be directly called, it feels Python is worth to learn, after all, can not write something to do a project it?
Pre-Preparation:
1, I am a computer win7 64, the estimated use of Windows computer situation is similar, after all, the bottom of the operating system food chain;
2, install Python, I went to the official website found 3.6.5 version is the latest, then it, specific how to install, too simple, download the corresponding version, and then install the time selected on the automatic Configuration environment variables, installation is directly can use, do not repeat;
3, use PIP to install MySQL required pymysql module, Oracle needs the Cx_oracle module:
Pip install Pymysql;pip install cx_oracle;
4, (MySQL user skipped directly) do you think the Oracle connection is done? It must be impossible to install the instant client:
(1) Open this page first, this is the Oracle website to provide download instantclient place: http://www.oracle.com/technetwork/cn/topics/ Winx64soft-101515-zhs.html, and choose to accept the agreement after downloading the following file can be;
(2) Unzip the file, I extracted directly to the D disk, so my directory is: D:\instantclient_11_2
(3) Add environment variable: oracle_home, the value is the directory of the previous step;
(4) The value of the path variable is added last:%oracle_home%;
5, really trouble, access to Oracle is really annoying, but forgive him, after all, people under the eaves, experienced a step after the good, this time to put their own Python editor restart, I use the pychram here, restart will be able to access two kinds of databases, such as the following:
ImportPymysql as Mysql;db= Mysql.connect ("localhost","Root","Root","test2", charset='UTF8'); cursor=db.cursor () cursor.execute ("Select version ()");d ATA=Cursor.fetchone ();Print(data) db.close ();
When you run your code, you print your own version of the data:
(' 5.5.56-mariadb ',)
Well, today's essay is over, forget the Oracle code also come up, save the same as me novice do not know how to use Oracle:
Import= cx_oracle.connect ('root'password' ' LOCALHOST:1521/SVDP ' = db.cursor (); Cursor.execute ("select 1 from dual" = cursor.fetchone (); Print (data) db.close ();
Connect mysql/oracle using Python