国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL基本命令、常用命令總結

2024-07-24 12:47:30
字體:
來源:轉載
供稿:網友

啟動:net start mysql;
進入:mysql -u root -p/mysql -h localhost -u root -p databaseName;
列出數據庫:show databases;
選擇數據庫:use databaseName;
列出表格:show tables;
顯示表格列的屬性:show columns from tableName;
建立數據庫:source fileName.txt;
匹配字符:可以用通配符_代表任何一個字符,%代表任何字符串;
增加一個字段:alter table tabelName add column fieldName dateType;
增加多個字段:alter table tabelName add column fieldName1 dateType,add columns fieldName2 dateType;
多行命令輸入:注意不能將單詞斷開;當插入或更改數據時,不能將字段的字符串展開到多行里,否則硬回車將被儲存到數據中;
增加一個管理員帳戶:grant all on *.* to user@localhost identified by "password";
每條語句輸入完畢后要在末尾填加分號';',或者填加'/g'也可以;
查詢時間:select now();
查詢當前用戶:select user();
查詢數據庫版本:select version();
查詢當前使用的數據庫:select database();

1、刪除student_course數據庫中的students數據表:

復制代碼 代碼如下:
rm -f student_course/students.*

2、備份數據庫:(將數據庫test備份)

復制代碼 代碼如下:
mysqldump -u root -p test>c:/test.txt
備份表格:(備份test數據庫下的mytable表格)
mysqldump -u root -p test mytable>c:/test.txt
將備份數據導入到數據庫:(導回test數據庫)
mysql -u root -p test


3、創建臨時表:(建立臨時表zengchao)

復制代碼 代碼如下:
create temporary table zengchao(name varchar(10));

4、創建表是先判斷表是否存在

復制代碼 代碼如下:
create table if not exists students(……);

5、從已經有的表中復制表的結構

復制代碼 代碼如下:
create table table2 select * from table1 where 1<>1;

6、復制表

復制代碼 代碼如下:
create table table2 select * from table1;

7、對表重新命名

復制代碼 代碼如下:
alter table table1 rename as table2;

8、修改列的類型

復制代碼 代碼如下:
alter table table1 modify id int unsigned;//修改列id的類型為int unsigned
alter table table1 change id sid int unsigned;//修改列id的名字為sid,而且把屬性修改為int unsigned

9、創建索引

復制代碼 代碼如下:
alter table table1 add index ind_id (id);
create index ind_id on table1 (id);
create unique index ind_id on table1 (id);//建立唯一性索引

10、刪除索引

復制代碼 代碼如下:
drop index idx_id on table1;
alter table table1 drop index ind_id;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吉首市| 普宁市| 南川市| 楚雄市| 峡江县| 正阳县| 上虞市| 芮城县| 南充市| 方正县| 阜康市| 资溪县| 丹寨县| 河间市| 遵化市| 平遥县| 如东县| 开封市| 正阳县| 安图县| 密山市| 泽州县| 鲜城| 鹤岗市| 四川省| 望城县| 息烽县| 汝阳县| 华阴市| 常宁市| 贵德县| 个旧市| 嵊州市| 枣阳市| 米脂县| 三河市| 宜兴市| 栾川县| 蕲春县| 青田县| 咸宁市|