標籤:mysql 基礎命令
系統中命令
mysqlshow 查看mysql中的庫
mysqlshow 庫名 查看指定庫中的表
mysql中的命令
create 建立
create database 庫名; 建立庫
create table 表名 (列名 選項, 列名 選項, ...); 建立表
create 複製表 被複製表名:T1
建立表名:T2
create table T2 like T1; 複製表結構
create table T2 as select * from T1; 完全複製表(as可以不寫)
create table T2 as select id,name from T1; 複製指定列內容(as可以不寫)
create table T2 as select * from T1 where 列名=值; 複製指定條件的內容(as可以不寫)
show 查看資料庫結構
show databases; 查看存在的庫
show tables; 查看庫中存在的表
選項:full open
show full tables; 查看庫中檔案並標示是表或是視圖
show open tables; 查看系統中記憶體開啟的表
flush tables; 清空系統記憶體中開啟的表
show columns from 表名; 查看錶中列資訊
show fields from 表名; 查看錶中列資訊
show create table 表名\G 查看錶指定的屬性和表的具體資訊,註:這是唯一可以查詢表屬性的方法
describe
describe 表名; 查看錶結構每列的資料類型
可簡寫 desc 表名;
explain
explain t1; 非常強大的表編輯工具
select 查看資料
select database(); 查看所在的庫
查看錶內容
select * from 表名; 查看錶所有列內容
select 列1,列2 ... from 表名; 查看錶指定列內容,顯示列順序可以自行定義
select 指定列 from 表名 limit [指定起始行],顯示行數; 查看錶指定行內容,指定起始行預設第一行為“0”
select 指定列 from 表名 where 列名=值; 尋找指定內容的行,值是非數字時需加單引號
select 指定列 from 表名 where 列名 is null; 尋找表中指定列中的空值所在的行
use 登陸
use 庫名; 進入指定的庫
drop 刪除
drop database 庫名; 刪除庫
drop table 表名; 刪除表
insert into 插入資料
insert into 表名 (列1,列2,...)values (值1,值2,...); 向指定表中插入資料
insert into T2 select * from T1; 將T1表內容插入到T2表中
insert into T1 select * from T1; 將表中內容乘方複製
handler 查看資料
必須先開啟表才能查看資料
handler 表名 open [ [as] alias];
HANDLER tbl_name READ 列名 { = | <= | >= | < | > } (value1,value2,...)
[ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST }
[ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ { FIRST | NEXT }
[ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name CLOSE 閉表
rename table 表重新命名
rename table 舊錶名to 新表名; 表重新命名
truncate
truncate table 表名; 清空表內容
本文出自 “果然收到” 部落格,請務必保留此出處http://8850775.blog.51cto.com/8840775/1854723
mysql基礎命令