日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

mysql库操作、表操作

發(fā)布時間:2025/3/21 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql库操作、表操作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

系統(tǒng)數(shù)據(jù)庫
information_schema:虛擬庫,主要存儲系統(tǒng)中的一些數(shù)據(jù)庫對象的信息,例如用戶信息,列信息、權(quán)限信息等
performance_schema:主要存儲數(shù)據(jù)庫服務器的性能參數(shù)
mysql:授權(quán)庫,主要存儲系統(tǒng)用戶的權(quán)限信息
sys:主要存儲數(shù)據(jù)庫服務器的性能參數(shù)

創(chuàng)建數(shù)據(jù)庫:DDL
1、#mysqladmin -u root -p1 create db1
2、直接去創(chuàng)建數(shù)據(jù)庫目錄并且修改權(quán)限
3、mysql> create database db1;

數(shù)據(jù)庫命名規(guī)則:
1、區(qū)分大小寫
2、唯一性
3、不能使用關鍵字如:create select
4、不能單獨使用數(shù)字

查看數(shù)據(jù)庫:
mysql> show databases;
mysql>show create database db1;
mysql>select database();

切換數(shù)據(jù)庫:
mysql>use db1;
mysql>show tables;

刪除數(shù)據(jù)庫:
mysql>DROP DATABASE 數(shù)據(jù)庫名;


MySQl表操作
表是數(shù)據(jù)庫存儲數(shù)據(jù)的基本單位,由若干個字段組成,主要用來存儲數(shù)據(jù)記錄。

使用編輯器編輯指令:
mysql>edit
mysql>\e

在mysql客戶端內(nèi)執(zhí)行系統(tǒng)命令:
mysql>system ls
mysql>! ls

創(chuàng)建表:
mysql>create table t1(id int,name char(20),age int);
Query OK, 0 rows affected (0.03 sec)

語法:
create table 表名(
字段名 類型[(寬度)約束條件]
)[存儲引擎 字符集]
==在同一張表中,字段名是不能相同的
==寬度和約束條件可選
==字段名和類型是必須的

查看表(在當前所在庫)
mysql>show tables;
mysql>desc db1;
mysql>show create table db1;
mysql>show create table db1 \G;
mysql>show table status like 'db1' \G

查看表的內(nèi)容
mysql>select * from db1;
mysql>select name,age from db1;

修改表
alter 修改表名稱 修改字段名稱 修改字段數(shù)據(jù)類型 修改字段的修飾服
insert 插入數(shù)據(jù)
delete 刪除數(shù)據(jù)
update 更新數(shù)據(jù)

修改表名稱
mysql>rename table db1 to abc;
mysql>alter table abc rename db1;

添加新字段
mysql>alter table db1 add mat int(10);
mysql>alter table db1 add(chinese int(10),english int(10));

修改字段數(shù)據(jù)類型、修飾符
mysql>aler table db1 modify chinese in(5) not null;
修改名稱、數(shù)據(jù)類型、修飾符
mysql>alter table db1 change chinese china int(6);

刪除字段
mysql>alter table db1 drop en;

插入數(shù)據(jù)(添加記錄)
字符串必須引號引起來
mysql> insert into t1(id,name,math,china) values(1,"wing",80,90);
mysql> insert into t1(id,name,math,china) values(2,"king",70,100),(3,"tom",50,70);
mysql> insert into t1 values(4,"xiaosan",50,100);
mysql> insert into t1(id,math) values(5,70);
mysql> insert into t1 set id=6,math=65;
更新記錄
mysql>update db1 set name="lilei" where id=5;

刪除記錄
mysql>delete from db1 where id=6;
mysql>delete from db1;

表復制:key不會被復制:主鍵、外鍵和索引
mysql >create table db1(select * from t2);
mysql >delete table t10(select id,name from t2);

復制表結(jié)構(gòu)
mysql> create table t4(select * from t3 where 5=4);
mysql> create table t4(select id,name from t3 where 5=4);

復制記錄
mysql> insert into t3 select * from t10 where id=9;

刪除表
mysql> drop table t1;

刪除庫
mysql> drop database gnu;

轉(zhuǎn)載于:https://blog.51cto.com/13523981/2059995

總結(jié)

以上是生活随笔為你收集整理的mysql库操作、表操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。