Python+mysql Development Hospital Online reservation system (course design) One

Source: Internet
Author: User
Tags microsoft sql server

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
    • Start MySQL
service mysqld startsystemctl start Mysqld.service
    • Check MySQL status
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

    • The Python standard database interface for Python Db-api,python DB-API provides developers with a database application programming interface.

      The Python database interface supports a very great number of databases, and you can choose the database that works for your project:

      • Gadfly
      • MSQL
      • Mysql
      • PostgreSQL
      • Microsoft SQL Server 2000
      • Informix
      • Interbase
      • Oracle
      • Sybase
    • What is MYSQLDB?

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

    • Install MySQL:
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.