查看陳述句
-
查看所有資料庫
show databases; -
查看表結構
desc table_name; -
查看庫中所有表
show tables; -
查看建表陳述句
show create table <table_name> ;
新建表陳述句
- 新建表:
id int unsigned not null auto_increment comment '用戶id',
uesr_name varchar(20) not null comment '用戶名',
email varchar(50) not null comment '用戶郵箱',
age tinyint unsigned not null comment '用戶年齡',
fee decimal(10,2) not null default 0.00 comment '用戶余額',
created_at timestamp not null comment '注冊時間',
primary key(id) );
| Filed | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| id | int(10) | NO | PRI | NUll | auto_increment |
| uesr_name | varchar(20) | NO | NUll | ||
| varchar(50) | NO | NUll | |||
| age | tinyint | NO | NUll | ||
| fee | decimal(10,2) | NO | 0.00 | ||
| created_at | timestamp | NO | NULL |
- 字譯說明
- unsigned:無符號
- tinyint:最小int
- decimal:準確,不四舍五入
- timestamp:時間戳
- comment:備注
DDL:
alter table 修改表操作
alter table 表名 modify 列名 列型別 --修改改列型別
alter table 表名 change 原列名 新列名 列型別 --修改列名
alter table 表名 add 列名 列型別 ...alter **欄位后 放置位置 --添加列欄位
alter table 表名 drop 列名 --洗掉列欄位
alter table 表名 rename/rename to 新表名 --重名命表名
DML資料管理語言:
-
select陳述句
select * from 表名 -
insert陳述句
insert into插入表操作
insert into 表名 (列名,列名)values (‘’,‘’);
insert into 表名 values(‘’,‘’)需全部欄位都填上
password(‘123456’)密碼函式加密
show variables like '%char%' 查看字符編碼
set names gbk 設定字符編碼,解決中文亂碼顯示(當前鏈接改,退出后恢復) -
update陳述句
update 表名 set 列=‘’where 列=‘’
update 表名 set 列=‘’,列=‘’where 列=‘’
update 表名 set 列=‘’where 列!=‘’
update 表名 set 列=‘’where 列 in(1,2,4)
update 表名 set 列=‘’where 列 between 2 and 5 修改2到5之間的 -
delete陳述句
delete from 表名 where 列=‘’
delete from 表名;整表洗掉
truncate 表名;整表洗掉,重新插入id重新開始排
DCL資料控制語言:
-
修改密碼
1、update user set password-PASSWORD(‘新密碼’) where user=‘用戶名’
2、mysqladmin -uroot -p舊密碼 password 新密碼 -
忘記密碼
運行mysql.exe mysqld --skip-grant-tables 跳過權限,后臺開行程進入mysql
use mysql
select user,host,password from user
update user set password=password('新密碼') where user='用戶名'
flush privileges重繪權限
mysql -uu -
創建用戶
create user 用戶名 @‘IP地址’ identified by ‘密碼’
限定的IP上使用,所有IP要用%
mysql -u用戶名 -h地址 -p密碼 -
用戶授權
grant 權限1,權限2,... on 資料庫名.* to 用戶名 @IP地址或%
所有資料庫用. 所有權限用all/all privileges -
撤銷權限
revoke 權限1,權限2..on 資料庫名.* from 用戶名 @IP地址或%
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/61070.html
標籤:MySQL
上一篇:MySQL 支持的存盤引擎
