【Python】資料庫練習-1

來源:互聯網
上載者:User

標籤:sel   inno   刪除表   儲存   dex   values   book   練習   select   

三十四 資料庫

1、     查看資料庫命令

 

 

2、     使用某個資料庫

 

 

3、     查看當前在哪個庫

 

 

4、     查看當前資料庫中有哪些表

 

 

5、     查詢表中資料

 

 

6、     建庫:create database testbase;

7、     建表:create table user(id int not null);

 

 

 

建立表,名字為user_wangjing,欄位為 id,date1,date2等

 

 

 

 

 

建立表名,括弧裡意思是int 11位,不可為空

 

 

8、     插入資料:insert into user values(1);

 

9、     查看錶的資訊:

 

10、    刪除表

 

11、    刪除庫:drop database testbase;

12、    建立使用者:

create user ‘student11‘@‘%‘ identified by "gloryroad";

FLUSH PRIVILEGES;

 

%表示所有IP都可登入,‘student11‘@‘10.60.89.%‘表示只有這個欄位的IP可以登入

13、    修改密碼:

UPDATE USER SET PASSWORD=PASSWORD(‘12345622xw1‘) WHERE USER=‘gg1‘;

FLUSH PRIVILEGES;

14、    建立使用者和修改使用者的許可權

grant all privileges on test.user to [email protected]"%" identified by "gloryroad" ;  #讓使用者擁有操作任意資料庫的許可權

flush privileges;

15、    建表,插入值

 

ENGINE=InnoDB儲存資料庫採用innoDB引擎,如果你想使用外鍵,事務等功能,就需要innodb引擎

16、    查看錶的欄位和屬性: show columns from book_wangjing;

 

17、    查看索引:SHOW INDEX FROM book_wangjing;

 

18、    查看2條資料,從頭開始前兩條不看,列印接著後面的

 

19、    查看2條之後的3條

 

20、    查詢表資料 and or:

 

21、    給表中的欄位起一個別名

 

22、    表中欄位的排序

 

select * from book where book_author like ‘%老師‘;

計算表中資料條數:

 

計算平均值:

 

【Python】資料庫練習-1

聯繫我們

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