MySQL Experiment Preparation (i)--environment preparation

Source: Internet
Author: User
Tags python script

MySQL Experimental script preparation (a) the experimental environment in which Python manipulates the database
    • Install PIP
      1. download the script file

      [[email protected] .vnc]# wget https://bootstrap.pypa.io/get-pip.py

      2. View the PIP version

      [[email protected] .vnc]# pip --versionpip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

      3. Install Pyton mysqldb

      [[email protected] data]# pip install MySQL-python
MySQL 8.0 User & database & table creation
  • Creation of a database
    1. Database Creation

    createdatabase zdemo;use zdemo;

    2. statement view of the database

    createdatabase zdemo;+----------+----------------------------------------------------------------+DatabaseCreateDatabase                                                |+----------+----------------------------------------------------------------+ | zdemo    CREATEDATABASE/*!40100 DEFAULT CHARACTER SET utf8 */ |+----------+----------------------------------------------------------------+1rowinset (0.00 sec)
    The character set of the database is given by default and is now generally utf8.
  • Creation of tables
    1. Creating statements for tables

    CREATETABLE student (idintNOTNULL auto_increment,stu_id MEDIUMINT unsigned  NOTNULLCOMMENT‘学号id‘varchar(30NOTNULLCOMMENT‘姓名‘,PRIMARYKEY  (`id`));

    2. View of data table statements

    Mysql> ShowCreate Tablezdemo.student;+---------+------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---------------------------------------+|Table|Create Table|+---------+------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---------------------------------------+| Student |CREATE TABLE' Student ' (' ID ')int(Ten) unsigned not NULLAuto_increment, ' stu_id ' Mediumint (8) unsigned not NULL COMMENT ' Learning ID ', ' Stu_name 'varchar( -) not NULL COMMENT ' name ',PRIMARY KEY(' ID ')) Engine=innodbDEFAULTCharset=utf8 |+---------+------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---------------------------------------+  1 Row inch Set(0.00Sec
  • Create user
    1. User-created

    createuser [email protected]‘%‘IDENTIFIEDWITHBY‘[email protected]‘PASSWORDEXPIREINTERVAL360DAY;

    2. empowering the Zdemo database to be increased, deleted, changed, checked

    grantselect,insert,update,deleteonto [email protected]‘%‘;

    where [email protected]'% ' is matching all IP addresses can access this database, rights management should be set to [email protected]‘192.168.35.%‘ match only one segment, or a specified IP address due to the experimental environment. Safety is not too much to be considered.
    3. View user ZSD permissions

    mysql>Show grants for [email protected]'% ';+----------------------------------------------------------------+ | Grantsfor [email protected]%|+----------------------------------------------------------------+ | GRANTUSAGE on *. * To' ZSD '@`%`                                | | GRANTSELECT, INSERT, UPDATE, DELETE on' Zdemo '. * To' ZSD '@`%` |+----------------------------------------------------------------+2Rows in Set (0.01 sec)
Python link MySQL db instance
  • State of the experimental environment
    Client: 10.1.11.18
    MySQL server: 10.1.11.170
  • Python link instance statement

     #!/usr/bin/python  #-*-coding:utf-8-*- import  mysqldbdb Span class= "OP" >=  mysqldb. connect  ( "10.1.11.170" , , ,  "Zdemo" , Charset=   ' UTF8 ' ) cursor Span class= "OP" >=  db.cursor () cursor.execute ( "select VERSION ()" ) data =  cursor.fetchone () print   "Database version:  %s   " %  datadb.close ()  
  • Execution results

    [[email protected] data]# python test.pyDatabase version : 8.0.11

    Objective: To build the basic environment of client and database, the next section simply simulates the load by writing Python script, bulk inserting statements and query statements. The performance state variables of MySQL are collected through benchmark tests. Do analytical research

MySQL Experiment Preparation (i)--environment preparation

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.