MYSQL使用筆記

來源:互聯網
上載者:User

標籤: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使用筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.