创建查看修改数据库及数据表
一、創(chuàng)建使用MYSQL
1、通過shell終端激活MYSQL:通過Windows鍵+R打開代碼命令行(shell 腳本),輸入mysql -u root -p;回車,然后輸入密碼,回車,激活數(shù)據(jù)庫;
2、創(chuàng)建數(shù)據(jù)庫:create database 數(shù)據(jù)庫名;/* 數(shù)據(jù)庫名稱不能超過64位,有特殊字符或純數(shù)字需要用單引號(hào)/
3、創(chuàng)建數(shù)據(jù)庫判斷是否有重名的數(shù)據(jù)庫:create database if not exists 數(shù)據(jù)庫名;/
4、使用數(shù)據(jù)庫:use 數(shù)據(jù)庫名;
5、刪除數(shù)據(jù)庫:drop database 數(shù)據(jù)庫名;
6、顯示所有的數(shù)據(jù)庫:show databases;
7、退出MYSQL:quite;
二、MYSQL數(shù)據(jù)庫的表操作
1、創(chuàng)建表:create table tb1_name (id int(5) not null auto_increment ,
name varchar(8) null,
pasword varchar(20) default '默認(rèn)值字符型' not null,
primary key (id));
/*int():整數(shù)型;varchar():字符型;null:可以為null;not null:不可以為null;default?'默認(rèn)值字符型':默認(rèn)值;auto_increment:表示自動(dòng)增加,要和primary key相互對(duì)應(yīng);
2、查看表的屬性:describe tablename;
3、修改表的名字:rename table tb1_name to tb1_newname;
另一種:alter table tb1_name rename to tb1_newname;
alter table命令:更改已經(jīng)存在的表,修改表的名稱,添加、刪除、修改表的字段;
4、為表添加字段newcolunmname
alter table tb1_name add newcolumnname varchar (255) not null;/*add 關(guān)鍵詞,增加字段
5、修改字段定義
alter table tb1_name change id newid int(5);/*change關(guān)鍵詞,修改字段定義
6、刪除字段
alter table tb1_name drop email;/*drop 命令
7、刪除表
drop table tb1_name;
三、獲取數(shù)據(jù)庫和表的信息
1、顯示MYSQL中的數(shù)據(jù)庫:show databases;
2、查看某個(gè)數(shù)據(jù)庫中有多少表:use 數(shù)據(jù)庫名;show tables; ? ?或者 show tables from 數(shù)據(jù)庫名;
3、查看表中內(nèi)容:describe (數(shù)據(jù)庫名.)表名;
?
轉(zhuǎn)載于:https://www.cnblogs.com/smallcrystal/p/4990089.html
總結(jié)
以上是生活随笔為你收集整理的创建查看修改数据库及数据表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [官方教程] [ES4封装教程]1.使用
- 下一篇: ubuntu15.04中安装mysql和