MySQL常用命令-增刪改查

MySQL常用命令-增刪改查

MySQL常用命令

指令作用

指令

查看/查詢

show,select,desc

創建

create

刪除

drop,delete,truncate

切換/進入

use

添加記錄

insert

查看數據庫列表

show databases;

查看當前數據庫登入的是那個用戶

select user();

查看當前數據庫有哪些表

show tables;

查看test數據庫的編碼類型

show create database test;

查看test表的類型

show create table test;

查看test表的定義信息

desc test;

創建數據庫

create database db1;

創建一個utf8mb4類型的數據庫

create database db2 DEFAULT CHARACTER SET utf8mb4;

創建表

CREATE TABLE students (id int UNSIGNED NOT NULL PRIMARY KEY,name VARCHAR(20)NOT NULL,age tinyint UNSIGNED);

為emp表添加記錄(有 id,name,sex,age字段)

insert into emp (id,name,sex,age) values(1,'xiaoming','m',30);

修改emp表的內容(第幾行第幾個字段)

update emp set age=18 where id=4;

刪除數據庫

drop database db1;

刪除test表

drop table test

刪除emp表中的記錄

delete from emp where name='lvdou';

刪除emp整個表記錄

delete from emp;

備註:這個命令要是刪除上萬條記錄很慢(因為他記錄日誌,可以利用日誌還原)

truncate table emp;這個命令刪除上萬條記錄特別快

因為他不記錄日誌

清空emp表

truncate table emp;

批量執行sql程序

mysql < hellodb_innodb.sql

備註:也可不進入數據庫的情況下查看數據庫

mysql -e 'show databases'


分享到:


相關文章: