One: Configuration of the development environment
1: Desktop environment for cnetos+python2.7
Installation and configuration of 2:mysql
1) Installation of MySQL
- MySQL Official document: http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
- MySQL Yum Download: http://dev.mysql.com/downloads/repo/yum/or download directly with Weget:
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
- To install the software source:
sudo rpm-uvh mysql57-community-release-el7-noarch.rpm
- Installing the MySQL server
Yum Install -Y Mysql-community-server
service mysqld startsystemctl start Mysqld.service
Service mysqld statussystemctl Status Mysqld.service
This means that MySQL is running successfully.
- To modify the temporary password:
- Get a temporary password for MySQL
To enhance security, MySQL5.7 randomly generates a password for the root user, in error log, about the location of the error log and, if the RPM package is installed, the default is/var/log/mysqld.log. You can only view the temporary password once you have started MySQL once.
grep ' Temporary password ' /var/log/mysqld.log
(如果之前安装过MySQL则这里可能会有多个密码,用最后一个,注意这个密码输入时是可以粘贴的)
This password has been encrypted, can be copied, followed directly with
- Login and change your password
Mysql-uroot-p
(这是一个MySQL的以密码登录root用户的命令)
After logging on to the server with this password, you must modify the password and perform some database operations immediately, or you will get the following error:
Select1820 (HY000): You must reset your password using ALTER USER statement before executing th is Statement.mysql>
-
Change the password (note that it is best to have a post-logon operation; end)
' Root '@'localhost'root123';
-
- If the password settings are too simple, the following prompt appears
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
How to solve ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
it?
Two global parameters must be modified:
First, modify the value of the Validate_password_policy parameter
Mysql> set global validate_password_policy=0;
Change the length of the password again
Set global validate_password_length=1;
Execute the change password again.
' Root '@'localhost'root123';
(ALTER等可以写成小写)
3:python working with MySQL database
MYSQLDB is the interface for the Python link MySQL database, which implements the Python database API specification V2.0, built on the MySQL C API.
python2.* version can use MYSQLDB, but does not support Python3,python3 has a pymysql, detailed installation method see here
Yum Install Mysql-python
Be sure to pay attention to the case of the egg.
- After the installation is complete, in Python
Import MySQLdb
No error will prove the module installation is complete
4: Database connection
Before you connect to a database, verify the following:
- You have created the database TESTDB.
- In the TestDB database, you have created table EMPLOYEE
- The Employee table fields are first_name, last_name, age, SEX, and INCOME.
- Connection database TestDB Use the user name "TestUser", the password is "test123", you can set your own or directly use the root user name and its password, MySQL database user authorization please use the GRANT command.
- The Python mysqldb module is already installed on your machine.
#!/usr/bin/python#-*-coding:utf-8-*-ImportMySQLdb#Open a database connectiondb = MySQLdb.connect ("localhost","testuser","test123","TESTDB", charset='UTF8' )#get an operation cursor using the cursor () methodcursor =db.cursor ()#executing SQL statements using the Execute methodCursor.execute ("SELECT VERSION ()")#Use the Fetchone () method to get a single piece of datadata =Cursor.fetchone ()Print "Database version:%s"%Data#To close a database connectionDb.close ()
Execute the following script to output the result:
Database 5.0. $
Python+mysql Development Hospital Online reservation system (course design) One