mysql常用sql語句

2022-05-29 17:15:11 字數 1551 閱讀 8787

mysql常用sql語句

show variables like '%max_connections%'; //檢視資料庫的最大連線數;

set global max_connections=2000;//設定最大連線數,重啟後失效,永久生效需要在配置檔案中修改。

show  processlist;//連線詳細資訊

show status like 'threads%';//檢視連線線程數

show procedure status;//檢視儲存過程

select count(*) as total from table_name;//檢視表有多少條資料

desc table_name; //檢視表結構

show table status where comment='view';//檢視檢視

show index from table_name;// 檢視索引

show variables like 'slow_query%';//檢視慢查詢的日誌路徑,以及是否開啟慢查詢。off為未開啟

show variables like '%version%';檢視資料庫的版本資訊

檢視正在執行的事務:

select

trx_id as '事務id',

trx_state as '事務狀態',

trx_requested_lock_id as '事務需要等待的資源',

trx_wait_started as '事務開始等待時間',

trx_tables_in_use as '事務使用表',

trx_tables_locked as '事務擁有鎖',

trx_rows_locked as'事務鎖定行',

trx_rows_modified  as '事務更改行'  

from information_schema.innodb_trx;

檢視正在鎖的事務:

select

lock_id as '鎖id',

lock_trx_id as '擁有鎖的事務id',

lock_mode as '鎖模式',

lock_type as '鎖型別',

lock_table as '被鎖的表',

lock_index as '被鎖的索引',

lock_space as '被鎖的表空間號',

lock_page as '被鎖的頁號',

lock_rec as '被鎖的記錄號',

lock_data as '被鎖的資料'

from information_schema.innodb_locks;

檢視正在等待的事務:

select

requesting_trx_id as'請求鎖的事務id',

requested_lock_id as '請求鎖的鎖id',

blocking_trx_id as '當前擁有鎖的事務id',

blocking_lock_id as '當前擁有鎖的鎖id'

from information_schema.innodb_lock_waits;

MySql 常用SQL語句

create database kali use kali show tables create table students sno varchar 10 primary key,sname varchar 10 not null,varchar 2 check in 男 女 age varcha...

常用sql語句(mysql)

給表新增列 sql alter table table name add column col name varchar 255 not null default default value 增加表列,指定格式 sql alter table table name add col name bool...

MySQL常用SQL語句

查詢一張表中的所有資料 sql view plain copy select from table name 查詢一張表中的指定列資料 sql view plain copy select column a,column b from table name 按條件查詢一張表中的所有資料 sql vi...