mysql常用操作命令收集

來源:互聯網
上載者:User

標籤:

查看串連數

show processlist; 也可以查information_schema.processlist表

查看定義/預設的參數

show variables like ‘%參數名字%‘;

取消使用者權限:

revoke SELECT, EXECUTE, SHOW VIEW ON `tsdp`.* from  ‘tsdp_ro‘@‘10.58.%.%‘  ;

更改參數

set session 參數名字=值;

set global 參數名字=值;

查看狀態值

show global status;

show status like ‘%參數名字%‘;

查看同步狀態

show slave status\G 做主從同步 change master to.....

建立使用者/賦予許可權

create user [email protected]‘111.111.111.111‘ identified by ‘123456‘;

grant all on clus.* to [email protected]‘111.111.111.111‘;

查看觸發器

use clus;

show triggers;

show create trigger triggername; 可以在information_schema.trigger差看

查看預存程序

use clus;

show procedure status;

show create procedure procedurename;

查看event

use clus;

show events;

show create event eventname;

建庫

CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

 

添加欄位

alter table tablename add column name varchar(10);

添加自增主鍵欄位

alter table tablename add column `ID` int primary key auto_increment;

修改欄位類型

alter table tablename modify column name varchar(10);

刪除欄位

alter table tablename drop clumn name;

索引

alter table tablename add index index_name (欄位);

alter table tablename drop index index_name;

create index index_name on tablename(欄位);

drop index index_name on tablename;

主鍵

alter table tablename add primary key (`ID`) auto_increment;

1.alter table tablename modify column `ID` int

 

2.alter table tablename drop primary key (`ID`);

鎖庫備份

/usr/local/mysql/bin/mysqldump -uroot -p‘vxxx‘ -h127.0.0.1 -P3306 --databases 庫名 --lock-all-tables --master-data > axx_20130607.sql 不鎖就去掉--lock-all-tables --master-data

 

錯誤連結過多,mysqld中斷主機所有請求,恢複可請求狀態

mysqladmin flush-hosts

 

查看使用者資源限制情況

select Host,User,Password,max_questions,max_updates,max_connections,max_user_connections from mysql.user;

 

轉換Myisam引擎到Innodb

alter table your_table_name engine=‘Innodb‘;

 

查看是否有使用Myisam引擎的表結構

select * from information_schema.tables where TABLE_SCHEMA not in (‘mysql‘,‘information_schema‘,‘performance_schema‘) and engine != ‘InnoDB‘;

 

匯出表結構

mysqldump -u*** -p -d your_database_name > database_structure.sql

 

查看user許可權

show grants for [email protected]‘127.0.0.1‘;

 

為一個使用者修改許可權

 

UPDATE mysql.user SET Grant_priv=‘Y‘, Super_priv=‘Y‘ WHERE User=‘root‘; 
FLUSH PRIVILEGES;

 

mcluster限制檢查sql
SELECT DISTINCT       CONCAT(t.table_schema,‘.‘,t.table_name) as tbl,       t.engine,       IF(ISNULL(c.constraint_name),‘NOPK‘,‘‘AS nopk,       IF(s.index_type = ‘FULLTEXT‘,‘FULLTEXT‘,‘‘as ftidx,       IF(s.index_type = ‘SPATIAL‘,‘SPATIAL‘,‘‘as gisidx  FROM information_schema.tables AS t  LEFT JOIN information_schema.key_column_usage AS c    ON (t.table_schema = c.constraint_schema AND t.table_name = c.table_name        AND c.constraint_name = ‘PRIMARY‘)  LEFT JOIN information_schema.statistics AS s    ON (t.table_schema = s.table_schema AND t.table_name = s.table_name        AND s.index_type IN (‘FULLTEXT‘,‘SPATIAL‘))  WHERE t.table_schema NOT IN (‘information_schema‘,‘performance_schema‘,‘mysql‘)    AND t.table_type = ‘BASE TABLE‘    AND (t.engine <> ‘InnoDB‘ OR c.constraint_name IS NULL OR s.index_type IN (‘FULLTEXT‘,‘SPATIAL‘))  ORDER BY t.table_schema,t.table_name;

 

來源資料庫mysql特性統計

select from mysql.func;select from information_schema.ROUTINES where ROUTINE_SCHEMA = ‘win4‘;select from mysql.event;select from information_schema.EVENTS where EVENT_SCHEMA = ‘win4‘;select from mysql.proc;select from information_schema.VIEWS where TABLE_SCHEMA = ‘win4‘;select from information_schema.TRIGGERS where TRIGGER_SCHEMA = ‘win4‘;select from information_schema.tables where table_schema= ‘win4‘ and engine != ‘InnoDB‘;select from information_schema.STATISTICS where table_schema = ‘win4‘ and INDEX_TYPE in (‘FULLTEXT‘,‘SPATIAL‘);select t.table_schema,t.TABLE_NAME,c.CONSTRAINT_TYPE from information_schema.tables t left join information_schema.TABLE_CONSTRAINTS c on t.TABLE_SCHEMA = c.TABLE_SCHEMA and t.TABLE_NAME = c.TABLE_NAME and c.CONSTRAINT_TYPE = ‘PRIMARY KEY‘ where t.TABLE_SCHEMA = ‘win4‘ and c.CONSTRAINT_TYPE is null;

 

mysql常用操作命令收集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.