Python operations Oralce / MySQL database

The first step: Python Oracle database operation

Total: divided into 2 parts
VM good oracle database has been installed
virtual machine is not installed oracle database

Premise: the virtual machine has been installed Python3

The first: the virtual machine has been installed good oracle

(1) check and modify Oracle environment variables, adding Python installation path to the environment variable;
(2) extracting cx_oracle package, and compile and mounting operation;
(3) into the python environment, the leader packet and checks whether the installed;
(4) connecting to the database;
(5) execute SQL statements stored procedure;
(6) closes the connection;

The second: the virtual machine is not good oracle installation

(1) and installing the lightweight client SDK database;
(2) check and modify Oracle environment variable added to the Python installation path environment variable;
(3) extracting cx_oracle package, and compile and mounting operation;
(4 ) into the python environment, the leader packet and check installed;
(5) connecting to the database;
(6) and execute SQL statements stored procedure;
(7) closes the connection;

Focus: method of operating oracle database. For example: create a connection, cursor, insert data, delete data, view databases.

Step two: Python MySQL database operations

Total: divided into 2 parts
virtual machine has been installed MySQL database and created a database and tables corresponding
virtual machine is not installed MySQL database and created a database and corresponding table

Premise: the virtual machine has been installed Python3

The first: the virtual machine been installed MySQL database and created a database and corresponding table

(1) extracting pymysql package and install;
(2) into the python environment, the leader packet and check installed;
(3) connected to a database;
(4) execute SQL statements and stored procedures;
(5) closes the connection;

The second: the virtual machine is not installed MySQL database and created a database and corresponding table

(1) extracting pymysql package and install;
(2) install the MySQL database and the corresponding database is created and the table, in the specific steps Hadoop textbooks;
1. Unpack and install three MySQL package;
2. Set the root password;
3. Start MySQL service;
4. landing mysql -uroot -proot, after entering the SQL prompt
5. Check whether the database contains testdb: show databases; (Note: the implementation of the database is displayed, first set the password in accordance with the statement following the mysql -uroot -proot) . Without this database, you will have to recreate;
6. Create database: the testdb the Create Database;
7. The database: the Use the testdb;
8. The created table: Create table employee (first_name char ( 20) not null, last_name char (20), int Age, Sex char (. 1), a float Income);
9. the display table: the Show tables;
10. the display structure: Asc Employee;
11. the authorization: Grant * All the testdb ON to the root @ localhost;.
12. the far, the table to be created;

(3) into the python environment, good leader packet and check installation;
(4) connected to a database;
(5) execute SQL statements stored procedure;
(6) closes the connection;

Focus: method of operating a MySQL database. For example: create a connection, cursor, insert data, delete data, view databases.

Published 21 original articles · won praise 6 · views 8013

Guess you like

Origin blog.csdn.net/weixin_42128329/article/details/100268043