常用mysql語法 Mysql一些常用的語法

2021-10-19 06:23:18 字數 1351 閱讀 4673

一.

show databases; #檢視有哪些資料庫

use cashloantest; #切換到該資料庫

select database(); #檢視當前所使用的資料庫

show tables;

delete from 表名; #刪除表的所有記錄資料(注:執行命令set sql_safe_updates = 0; 後才能刪除)

set sql_safe_updates = 0;

delete from user where id = 1; #刪除id為1的資料記錄

drop table table_name ; #刪除該錶

drop database 庫1 : 刪除庫

3.更新記錄

set sql_safe_updates = 0;

update tablename set age='newage' where name="alex"; #更新表裡面某個欄位的值

update sms_conf set name='nx',des=2 where id=1 #更新多個欄位的值

4.在指定的列後面加一列

alter table test add address varchar(110) not null default 'sb' after id; #在id列後面加一列address ,預設值為"sb"

二.1.mysql中replace與replace into的用法

distinct用法

id product_id

1 11

2 22

3 null

4 22

select distinct product_id from test 得到:

product_id

null

count(字段) 和 count() 區別:count(字段) 欄位為null的都無視,不記錄的,而count()會把每一條記錄都算上,不管null還是什麼

select count(product_id) from test

select count(distinct product_id) from test

三.1.mysql查一張表有哪些索引

show index from table_name;

2.新增index(普通索引) :

alter table table_name add index index_name ( column )

四.1.檢視mysql版本

select version() from dual;

2.檢視mysql檢視查詢快取是否啟用

show variables like '%query_cache%';

各個字段詳解:

mysql常用語法 MySQL常用語法

更新資料 update 表名 set 健名 更改的值 where 建 刪除資料 delete from 表名 where 索引 create index 索引名稱 on 表名 鍵名 建立試圖 create view 檢視名 鍵,鍵 as select matchno,abs won lost fro...

mysql基本常用語法 mysql 常用語法

1.1.開啟 service mysql start 1.2.關閉 service mysql stop 1.3.重啟 service mysql restart 2.1.密碼明文 語法 mysql u使用者名稱 p使用者密碼 舉例 mysql uroot p123456 2.2.密碼密文 語法 m...

MY sql 常用語法

mysql show databases mysql create database mysqldata mysql use mysqldata mysql show tables 4 建立資料庫 bin mysql uroot p mysql create database mysqldata m...