About the MySQL learning case under Python

Source: Internet
Author: User

1. Download MySQL

Baidu Search MySQL installation package Http://rj.baidu.com/soft/detail/12585.html?ald

(Note: Oracle installation is very troublesome, download need to register an account or something, also need to buy, so directly under the Baidu search installed, not enough to download the green installation version, need to configure MySQL)

Configuration conditions:

The installation directory is: F:\mysql-5.6.24-win32

2. Settings

2.1 Modify the My.ini file

[Client]

port=3306
Default-character-set=utf8
#客户端字符类型, consistent with the service side, recommended UTF8
[Mysqld]
port=3306
Character_set_server=utf8
#服务端字符类型, it is recommended that UTF8

Basedir=f:\mysql-5.6.24-win32
#解压根目录

Datadir=f:\mysql-5.6.24-win32
#解压根目录 \data

Sql_mode=no_engine_substitution,strict_trans_tables
[Winmysqladmin]
F:\mysql-5.6.24-win32\bin\mysqld.exe
#解压根目录 \bin\mysqld.exe

2.2 New Mysql_home

Edit the Path environment directory at the end of the add;%mysql_home%\bin (be careful not to lower the front; semicolon)

2.3 go to cmd

Details: http://jingyan.baidu.com/article/3f16e003ca8f0e2591c10337.html

Refer to the information on Baidu: The main my installation directory is in the F disk F:\mysql-5.6.24-win32

Start MySQL service: net start MySQL * This is the other one that is going to be started temporarily does not need to move

Stop MySQL service: net stop MySQL

Move out of MySQL service: mysqld–remove

2.4 Change root password (Here I set the local password is the root account is also root)

This means update user set PASSWORD (' root ') where user = ' root '

3. now go back inside the Pycharm .

#coding =utf-8
ImportMySQLdb

Conn= MySQLdb.connect (
host=' localhost ',
Port= 3306,
User=' Root ',
Passwd=' Root ',
db=' Test ',
)
cur = conn.cursor ()

#Create a data table
#cur. Execute ("CREATE TABLE student (ID int, name varchar (), class varchar (), Agevarchar (10))")

#插入一条数据
Cur.execute ("Insertinto Student Values (' 2 ', ' Tom ', ' 3 Year 2 class ', ' 9 ')")


#Modifying the data for a query condition
Cur.execute ("Updatestudent set class= ' 3 Year 1 class ' WHERE name = ' Tom '")

#Delete data for a query condition
#cur. Execute ("Delete from student where age= ' 9")

Cur.close ()
Conn.commit ()
Conn.close ()

About the MySQL learning case under Python

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.