關於Python下Mysql學習案例

來源:互聯網
上載者:User

標籤:

1.下載Mysql

    百度搜尋Mysql安裝包 http://rj.baidu.com/soft/detail/12585.html?ald

    (備忘:Oracle下安裝很麻煩,下載一下需要註冊賬戶什麼的,還需要購買,所以直接下百度下搜尋安裝了,不夠下載的綠色安裝版本,需要對Mysql進行配置)

    配置情況:

安裝目錄是:F:\mysql-5.6.24-win32

 

2.設定

2.1修改my.ini檔案

[client]

port=3306
default-character-set=utf8
#用戶端字元類型,與服務端一致就行,建議utf8
[mysqld]
port=3306
character_set_server=utf8
#服務端字元類型,建議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建立MYSQL_HOME

 

編輯PATH環境目錄  在最後添加;%MYSQL_HOME%\bin (注意不要少了最前面的;分號)

 

2.3進入cmd

詳情:http://jingyan.baidu.com/article/3f16e003ca8f0e2591c10337.html

參考了百度上的資料:主要我的安裝目錄是在F盤F:\mysql-5.6.24-win32

 

 

啟動MYSQL服務:net start mysql * 這個是要啟動的  其他的暫時不需要動

停止MYSQL服務:net stop mysql

移出mysql服務:mysqld –remove

 

2.4修改Root密碼  (這裡我設定本地的密碼是root 帳號也是 root)

意思就是update User set PASSWORD(‘root’) where User =’root’

 

3.現在回到PyCharm 裡面

#coding=utf-8
import MySQLdb

conn= MySQLdb.connect(
        host=‘localhost‘,
        port= 3306,
        user=‘root‘,
        passwd=‘root‘,
        db=‘test‘,
        )
cur = conn.cursor()

#建立資料表
#cur.execute("create table student(id int ,name varchar(20),class varchar(30),agevarchar(10))")

#插入一條資料
cur.execute("insertinto student values(‘2‘,‘Tom‘,‘3 year 2 class‘,‘9‘)")


#修改查詢條件的資料 
cur.execute("updatestudent set class=‘3 year 1 class‘ where name = ‘Tom‘")

#刪除查詢條件的資料
#cur.execute("delete from student where age=‘9‘")

cur.close()
conn.commit()
conn.close()

 

關於Python下Mysql學習案例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.