mysql基本語句

2021-08-25 02:44:07 字數 2294 閱讀 8849

建立資料庫

create database 《資料庫名》   例如:create database mydb

顯示資料庫

show databases;//注意是databases 不是database. 

建立資料表

create table 《表名》    例如:create table user_tb;

刪除資料庫

drop database 《資料庫名》    例如:drop database mydb;

刪除資料表

drop table 《表名》     例如:drop table user_tb;

資料表增、刪、查、改

(1)insert into《資料表名》(《列1>,《列2>,...)values(值1,值2,...)

例:insert into user_tb values("1","username",..."*");

(2)delete from 《資料表名》 where 《條件表示式》;

例:delete from user_tb where id="1";

(3)select 《選擇式》 from 《資料表名》 where 《條件表示式》;

select username from user_tb where id="1";

(4)update 《表名》 set 《字段》=《值》 where 條件表示式;

例:update user_tb set username="wang" where id="1";

分配使用者及許可權

grant select,insert,update,delete,create,drop,alter on 資料庫名.* to 資料庫名@localhost identified by '密碼';

增加字段

alter table表名add字段 型別 其他;

alter table 《表名》 add 《字段》 《型別》 《其他》

alter table user_tb add passtest int(4) default "0」;

備份資料庫

mysqldump -u 使用者名稱 -p資料庫名》匯出的檔名//匯出整個資料庫

mysqldump -u 使用者名稱 -p資料庫名 表名》匯出的檔名//匯出一張表

mysqldump -u 使用者名稱 -p -d -add -drop -table 資料庫名》匯出的檔名//匯出資料庫結構

例項1

drop database if exists school; //如果存在school則刪除

create database school; //建立庫school

use school; //開啟庫school

create table teacher //建立表teacher

(id int(3) auto_increment not null primary key,

name char(10) not null,

address varchar(50) default 『深圳』,

year date

); //建表結束

//以下為插入字段

insert into teacher values(」,』allen』,'大連一中』,'1976-10-10′);

insert into teacher values(」,』jack』,'大連二中』,'1975-12-23′);

例項2

dop database if exists school; //如果存在school則刪除

create database school; //建立庫school

use school; //開啟庫school

create table teacher //建立表teacher

(id int(3) auto_increment not null primary key,

name char(10) not null,

address varchar(50) default ''深圳'',

year date

); //建表結束

//以下為插入字段

insert into teacher values('''',''glchengang'',''深圳一中'',''1976-10-10'');

insert into teacher values('''',''jack'',''深圳一中'',''1975-12-23'');

mysql基本語句 mysql基本語句

mysql關係型資料庫rds中的老大哥,增刪改查是mysql入門的基礎 增刪改查語句 增刪改查的語句命令為 增 insert 刪 delete 改 update 查 select或者show 庫操作建立資料庫 create database shujukuba 建立帶字符集的資料庫 create d...

mysql了基本語句 MySQL基本語句大全

mysql指令碼的基本組成 與常規的指令碼語言類似,mysql 也具有一套對字元 單詞以及特殊符號的使用規定,mysql 通過執行 sql 指令碼來完成對資料庫的操作,該指令碼由一條或多條mysql語句 sql語句 擴充套件語句 組成,儲存時指令碼檔案字尾名一般為 sql。在控制台下,mysql 客...

MySQL基本語句

mysqld 啟動資料庫 mysql uroot 登陸使用者名稱或密碼 show databases 顯示所有資料庫 use 使用 資料庫 show tables 顯示該資料庫下的所有 select from table 查詢該錶 insert into table values 插入資料到表 de...