mysql数据库基本操作总结与归纳
生活随笔
收集整理的這篇文章主要介紹了
mysql数据库基本操作总结与归纳
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
mysql數(shù)據(jù)庫基本操作總結(jié)與歸納
登錄命令
mysql -u 用戶名 -p 密碼 列如; [root@localhost ~]# mysql -u root -p [root@localhost ~]# mysql -u root -pabc123登出命令
方法一:mysql> quit 方法二:mysql> exit 方法三:mysql> Ctrl + d數(shù)據(jù)庫操作
查看數(shù)據(jù)庫 select database; //查看當(dāng)前數(shù)據(jù)庫' show databases; //查看所有數(shù)據(jù)庫' 創(chuàng)建數(shù)據(jù)庫 use 數(shù)據(jù)庫名 //使用數(shù)據(jù)庫 create database 數(shù)據(jù)庫名 //創(chuàng)建數(shù)據(jù)庫 show create database 數(shù)據(jù)庫 '//查看創(chuàng)建數(shù)據(jù)庫的語句' drop databases 數(shù)據(jù)庫 //刪除數(shù)據(jù)數(shù)據(jù)庫表的操作
查看表 show tables 表名 //查看數(shù)據(jù)庫中表 create tables 表名 //創(chuàng)建數(shù)據(jù)庫表 show create table 表名 //查看創(chuàng)建的表 describe 表名; '//查看表結(jié)構(gòu)' select * from 表名 //查看表內(nèi)信息向表里插入信息 insert into 表名(字段1,字段2,…)values(字段1的值,字段2的值,…) //向表中插入記錄' update 表名 set 字段名 1=值1[,字段名2=值2] where條件表達(dá)式 '//修改數(shù)據(jù)記錄' 例如:update info set name='zhangsan'; '//修改所有的name'update info set name='zhang' where id=2 把id為2的姓名修改成zhangcrete table 表名 int(3)整型 000 - 999 not null '//表示不為空' primary key '//表示主鍵' auto_increment '//表示自動增長,步長為1' decimal (5,2) '//表示5個有效字符,2位小數(shù),例如100.00' default '//表示默認(rèn)值' varchar '//可變長字符'刪除表 drop table 表名 //刪除表 delete from 表名 //刪除表 delete from 表名 where條件表達(dá)式 //刪除指定記錄,不帶where條件的語句表示刪除表中所有記錄 列入; delete from tmp where score >=90 刪除大于等于90分的人 drop table [數(shù)據(jù)庫名.]表名 //刪除指定的數(shù)據(jù)表' truncate table 表名 //刪除表復(fù)制表 create table tmp as se lect * from benat; 查詢表 select 字段名1 from 表名; elect 字段名1 from 表名 where 條件表達(dá)式; 舉例:select score,address from benat; // select score,address from benat where id=2;創(chuàng)建索引
創(chuàng)建普通索引 create index <索引的名字> on tablename(列的列表); create index salary on IT_salary; 創(chuàng)建唯一性索引 create unique index <索引的名字> on tablename(列的列表); 創(chuàng)建主鍵索引 create table tablename([...],primary key(列的列表); 創(chuàng)建全文索引 create fulltext index <索引的名字> on tablename(列的列表); 查看索引 show index from tablename; show keys from tablename; 刪除索引 drop index index_name on table_name;總結(jié)
以上是生活随笔為你收集整理的mysql数据库基本操作总结与归纳的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 逃离神秘实验室:挑战记忆矩阵和速度迷宫
- 下一篇: 数据库高级查询