標籤:手動 use ceshi 類型 sel 欄位名 set new 命令
輸入命令注意:
1、命令結束符號是分號;
2、所有的符號都是英文半形
3、只有遇到分號 MySQL才人文結束
4、多個命令用分號隔開 create database stu;drop database stu
5、引號要打全 不然分號都不讓出
常用操作的單詞 : create(建立)、use(使用)、drop(刪除)、show(顯示)、databases(資料庫)、table(表)
一、在環境下開啟MySQL console
二、基本操作
1、顯示當前所有資料庫 show databases;
2、建立ceshi資料庫 create database ceshi;
手動修改資料庫的編碼格式:alter database ceshi character set utf8;
3、使用資料庫 use ceshi;
4、顯示資料庫中的表 show table;
備忘:資料類型
數字型:
整型:tinyint 1字元 2^8 1字元=256個位元組
int 4位元組 2^64
decimal(m,d) 定點型 m數位總長度
d小數的位元
decimal(5,2) 1.2896-1.29
999.123-999.12
字元型:
定長字元 char(255)
變長字元 varchar(255)
日期時間 datetime 8位元組 2018-06-01 09:05:01
主鍵:primary key
自增長列:auto_increment
非空:not null
預設值: default 值
5、建表
需要指明 資料類型 非空
每個表都要設定一個主鍵
create table myclass(
id int(4) not null primary key auto_increment,
name char(20) not null,
sex int(4) not null default ‘0‘,
degree decimal(16,2)
)
6、查看錶結構
desc myclass;
========================================================
show = 顯示
create = 創造
database = 資料庫
7、插入資料
insert into myclass values(‘‘,‘張寶中‘,‘‘,‘98.5‘);
8、查看錶中的資料
select * from myclass;
9、修改資料
update myclass set name = ‘張寶中‘ where id = 1;
10、刪除資料
delete from myclass where id = 1;
二、
alter table myclass + 語句
1、修改表名
rename as newcl;
2、添加欄位
add age int(4) not null;
add pid int(4) not null first; 在第一列添加pid
add selfsm char(255) not null after age; 在age列添加selfsm
3、修改欄位的名字和類型
change age newage char(20);
4、修改某一欄位的類型
modify column newage int(4);
5、添加預設值-如果有預設值,先刪除再添加
alter column newage drop default;
alter column newage set default 18;
6、刪除欄位
drop id;
7、添加主鍵
add primary key(欄位名);
8、刪除主鍵
drop primary key;
9、刪除表
drop table newcl;
show tables;
10、刪除資料庫
drop database ceshi;
show databases;(查看所有資料庫)
wamp中MySQL控制台的基本操作