標籤:span abc port read 輸入 多列 int select sql
1、下載,下載版本太多,不知道下哪個好,別人介紹版本
進入官網-->點擊最下面 DOWNLOADS-->選擇MySQL on Windows(installer & Tools)-->MySQL Installer-->選擇
Windows (x86, 32-bit), MSI Installer 5.7.20 376.3M (mysql-installer-community-5.7.20.0.msi) 我電腦是win10 64位,也不知道為什麼選擇32-bit
2、安裝,正常一步一步點擊安裝
3、MYSQL資料庫基本操作
import pymysqlimport pandas as pd#先做最基本的,再在實踐中慢慢調整最佳化#一、串連資料庫con=pymysql.connect(host=‘localhost‘,user=‘root‘,password=‘1***‘,database=‘world‘)cursor=con.cursor()#二、建立資料庫和表#建立資料庫# create_schema="create schema abc"# cursor.execute(create_schema)# #建立表# create_table=‘CREATE TABLE abc.Persons\# (\# Id_P int NOT NULL,\# LastName varchar(255) NOT NULL,\# FirstName varchar(255),\# Address varchar(255),\# City varchar(255)\# )‘# cursor.execute(create_table)#三、刪除表、刪除資料庫# drop_table="drop table abc.persons"# cursor.execute(drop_table)# drop_schema=‘drop schema abc‘# cursor.execute(drop_schema)#四、寫入資料insert_data="insert into abc.Persons values(1,‘a‘,‘b‘,‘c‘,‘d‘)"cursor.execute(insert_data)#五、刪除部分資料,如果某一行資料輸入錯誤,可以刪掉後再寫入#如果整個資料都要修改,可以刪掉表,建立表#1、刪除一行(多行或多列可以用迴圈)# drop_row=‘delete from abc.persons where Id_P=1‘# cursor.execute(drop_row)#2、刪除一列drop_column=‘alter table abc.persons drop column City‘ # alter table ***.*** drop column **cursor.execute(drop_column)#3、添加一列或幾列資料# add_column=‘alter table abc.persons add City varchar(255)‘# cursor.execute(add_column)con.commit()#六、讀取資料#querystringquerystring=‘SELECT * FROM sakila.actor‘#使用read_sql讀取資料data=pd.read_sql(querystring, con);print(data.head())
MYSQL使用筆記