mySql性能優化

 

 

查看數據庫的最大連接數

show VARIABLES like '%max_connections%'
set GLOBAL max_connections = 200
max_connections=151

查看是否開啓緩存

show variables like '%query_cache_type%'
SET GLOBAL query_cache_size = 4000;
SET GLOBAL query_cache_size = 134217728;

 

注:MYISIM也叫非聚集索引

 

show VARIABLES like 'innodb_file_per_table'
set global innodb_file_per_table=off

 

 

 

1. lock table testmysam READ 啓動另外一個session select * from
testmysam 可以查詢
2. insert into testmysam value(2);
update testmysam set id=2 where id=1;
報錯
3.在另外一個session中
insert into testmysam value(2); 等待
4.在同一個session中
insert into testdemo value(2,'2','3'); 報錯
select * from testdemo ; 報錯
5.在另外一個session中
insert into testdemo value(2,'2','3'); 成功
6.加索在同一個session 中 select s.* from testmysam s 報錯
lock table 表名 as 別名 read;
查看 show status LIKE 'table_locks_waited' 表被鎖過幾次

注:myisim索引的共享讀鎖說白了 就是鎖住了當前表,所有的讀操作是可以的,但是更新插入操作是需要等待鎖釋放後才能操作

        獨佔寫鎖則表示 其他的會話要操作當前表 ,必須要等到鎖釋放後才能操作,包括查詢和更新

 

也可以用工具來修改

注:關於鎖的理解可以在參考:  https://blog.csdn.net/localhost01/article/details/78720727

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章