資料庫入門

2021-05-25 09:26:20 字數 3154 閱讀 4895

今天講完自定義標籤和jstl後,我們下午就直接進入到資料庫方面的講解.首先佟老師給我們mysql資料庫的檔案教我們如何進行安裝,可能友人會說,安裝檔案還要講解,對,是的,如果在安裝過程中出現細小的疏忽,其最後的結果將會導致安裝失敗.這個安裝的步驟就不做詳細講解,就把容易出錯的地方說以下:

1.首先我們要選擇自定義安裝,第一自己能熟悉環境,二來可以配置自己想要的模式;

2.現在要選擇字符集一定要選擇gb2312.其他一概不考慮;

3.要考慮其埠,使用者名稱和密碼的設定;

對上面的幾個注意點掌握,安裝就算成功了.下面,佟老師給我門講解了資料庫的基本操作,說簡單也很簡單,就是最基本的增,刪,改,查.可是就真的就這麼簡單嗎?我可不認為,如果不細心的人運算元據庫時,會錯誤百出的,對於那些技術熟練的,確實是比較簡單的!今晚就先說說簡單的資料庫操作吧 !

1.進入 mysql, 在命令列中輸入: mysql –u root –p, 然後輸入密碼

2.檢視 mysq 中有那些個資料庫: show databases;

3.使用乙個資料庫: use 資料庫名稱;

4.新建乙個資料庫: create database 資料庫名

5.檢視指定的資料庫中有哪些資料表: show tables;

6.建表:  create table customer(

id varchar(30),

age int,

name varchar(30),

birthday date);

7.檢視表的結構:desc 表名

8.刪除表: drop table 表名

現在我們以下面的資料表作為基本操作的參考例子吧!

drop table if exists `customer`;

create table `customer` (

`id` varchar(20) default null,

`name` varchar(30) default null,

`age` int(11) default null,

`email` varchar(20) default null,

`birthday` date default null,

`salary` double default null

) engine=innodb default charset=gb2312;

insert into `customer` (`id`,`name`,`age`,`email`,`birthday`,`salary`) values ('10002','jerry',22,'[email protected]','1988-03-05',2000);

insert into `customer` (`id`,`name`,`age`,`email`,`birthday`,`salary`) values ('10001','tom',21,'[email protected]','1998-02-12',1000);

insert into `customer` (`id`,`name`,`age`,`email`,`birthday`,`salary`) values ('10003','bob',25,null,null,2500);

insert into `customer` (`id`,`name`,`age`,`email`,`birthday`,`salary`) values ('10004','mike',28,'[email protected]',null,2900);

insert into `customer` (`id`,`name`,`age`,`email`,`birthday`,`salary`) values ('10005','jack',31,null,'1987-09-18',3100);

1.查詢所有列: select * from 表名;

2.查詢特定的列: select 列名1,列名2, … from 表名

select id,name from customer;

3.對查詢的資料進行過濾:使用 where 子句

elect id,name from customer where age>21;

4.運算子:

select * from customer where salary >= 2000 and salary <=3000; //第一種方式

select * from customer where between 2000 and 3000;    //第二種方法

select * from customer where salary =2000 or salary =1000 salary  =3100; //第三種方式

select * from customer where salary in (1000,2000,3000);   //第四

5.查詢

name中有o

的人的名字

select * from customer where  name like '%o%';

6.查詢

name中第

3個字母是

r的人的名字

select * from customer where  name like '%__r%';

7.查詢

email為空

的所有人的資訊

select * from customer where  email is null;

8.查詢

email不為空

的所有人的資訊

select * from customer where  email  is not null;

9.查詢所有客戶資訊,且按

salary

公升序排列

select * from customer where  order by salary;

10.查詢所有客戶資訊,且按

salary

降序排列

select * from customer where  order by salary desc;

上面就是些最基本操作,但這些都是基礎,這些掌握了,才有進一步拓展的必要,否則的話,一切徒勞!

在傳智,或者確切的說,在佟老師的帶領下,我們在不斷的進步著,我個人感覺佟老師講的真好!有機會想向張老師提議,為講課老師講的好的,頒發相關榮譽證書!跟著佟老師學,心裡真踏實!星期6就要講jdbc 了,這個又是乙個很重要的知識點的!

期待!!!!!!!!!!!!!!!!!!!

資料庫入門

建立臨時表空間 create temporary tablespace user temp tempfile d database user temp.dbf size 50mautoextend on next 50m maxsize 20480m extent management local ...

資料庫入門

資料庫基本概念 介紹mysql 什麼是資料庫的正規化 mysql是乙個關係型資料庫管理系統,由瑞典mysql ab 公司開發,目前屬於 oracle 旗下產品。mysql 最流行的關係型資料庫管理系統,在 web 應用方面mysql是最好的 rdbms relational database man...

入門資料庫

資料庫入門 一 什麼是mysql?mysql是乙個關係型資料庫管理系統,由瑞典mysql ab 公司開發,目前屬於 oracle 旗下產品。mysql 是最流行的關係型資料庫管理系統之一,在 web 應用方面,mysql是最好的 rdbms relational database managemen...