楼主: mchdba

MySQL知识点技能点总结贴--个人版!

[复制链接]
招聘 : 数据库管理员
论坛徽章:
83
IT宝贝
日期:2013-11-15 18:40:242015年新春福章
日期:2015-03-06 11:57:31美羊羊
日期:2015-03-04 14:48:58马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11
71#
发表于 2011-10-21 16:47 | 只看该作者
已经记录了这么多,真是不容易,一定继续哦!
要把你的帖子推荐到论坛门户首页上

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
72#
 楼主| 发表于 2011-10-21 17:03 | 只看该作者

-- ===============================================================
-- Profiles
-- ===============================================================
一,查看profiles的状态值
   1,查看profiles是否已经打开了,默认是不打开的。
   mysql> show profiles;
   Empty set (0.02 sec)

mysql> show variables like '%pro%';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| have_profiling            | YES   |
| profiling                 | OFF   |
| profiling_history_size    | 15    |
| protocol_version          | 10    |
| proxy_user                |       |
| slave_compressed_protocol | OFF   |
+---------------------------+-------+
6 rows in set (0.00 sec)

   我查看一下profiles里面没有东西,所以公司服务器里面profile是没有打开的,我查看了一下mysql变量,果然是OFF的。

二,打开profiles,然后测试
  1,开启profiles
  mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)

  2,check下状态值,果然已经开启了,为ON
mysql> show variables like '%pro%';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| have_profiling            | YES   |
| profiling                 | ON    |
| profiling_history_size    | 15    |
| protocol_version          | 10    |
| proxy_user                |       |
| slave_compressed_protocol | OFF   |
+---------------------------+-------+
6 rows in set (0.00 sec)

  3,测试
mysql> drop table if exists test_cpny.listed_cpny_fin_rpt_prd;
Query OK, 0 rows affected (0.08 sec)

mysql> create table test_cpny.listed_cpny_fin_rpt_prd
    ->  SELECT dat.*
    ->     FROM test.qa_cpny es
    ->     inner join cdp.listed_cpny_fin_rpt_prd dat
    ->     on (es.excel_id = dat.excel_id)
    ->    ;
Query OK, 60960 rows affected (30.00 sec)
Records: 60960  Duplicates: 0  Warnings: 0

mysql>
  
  4,查看结果值:
mysql> show profiles;
+----------+------------+-------------------------------------------------------------------------------------------------

----
| Query_ID | Duration   | Query
+----------+------------+-------------------------------------------------------------------------------------------------

----
|        1 | 0.00044300 | show variables like '%pro%'
|        2 | 0.05818800 | drop table if exists test_cpny.listed_cpny_fin_rpt_prd
|        3 | 30.0030300 | create table test_cpny.listed_cpny_fin_rpt_prd
SELECT dat.*
    FROM test.qa_cpny es
    inner join cdp.listed_cpny_fin_rpt_prd dat
    on (es.excel_id = dat.excel_id) |
+----------+------------+-------------------------------------------------------------------------------------------------

----
3 rows in set (0.00 sec)

mysql>

  5,再check
mysql> show profile for query 3;
+------------------------------+----------+
| Status                       | Duration |
+------------------------------+----------+
| starting                     | 0.000072 |
| checking permissions         | 0.000007 |
| checking permissions         | 0.000003 |
| checking permissions         | 0.000007 |
| Opening tables               | 0.000161 |
| System lock                  | 0.000013 |
| init                         | 0.000006 |
| checking permissions         | 0.000065 |
| creating table               | 0.003520 |
| After create                 | 0.000089 |
| System lock                  | 0.000011 |
| optimizing                   | 0.000011 |
| statistics                   | 0.000016 |
| preparing                    | 0.000010 |
| executing                    | 0.000003 |
| Sending data                 | 29.96599 |
| Waiting for query cache lock | 0.000014 |
| Sending data                 | 0.010215 |
| end                          | 0.000016 |
| query end                    | 0.000004 |
| closing tables               | 0.000016 |
| freeing items                | 0.000042 |
| logging slow query           | 0.000004 |
| cleaning up                  | 0.000004 |
+------------------------------+----------+
24 rows in set (0.00 sec)

看来时间消耗在| Sending data                 | 29.96599 |上面啊!

使用道具 举报

回复
论坛徽章:
14
2011新春纪念徽章
日期:2011-04-02 17:01:062013年新春福章
日期:2013-02-25 14:51:24复活蛋
日期:2012-12-06 19:27:46ITPUB 11周年纪念徽章
日期:2012-10-09 18:16:00ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:42紫蛋头
日期:2012-03-13 16:37:18灰彻蛋
日期:2012-02-06 14:20:122012新春纪念徽章
日期:2012-01-04 11:57:56灰彻蛋
日期:2011-12-26 14:20:13茶鸡蛋
日期:2011-12-20 15:00:13
73#
发表于 2011-10-24 16:56 | 只看该作者
呵呵,写这么多啦,加油哦

使用道具 举报

回复
论坛徽章:
281
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-01-04 11:51:22蛋疼蛋
日期:2011-12-29 07:37:22迷宫蛋
日期:2011-12-26 14:19:41茶鸡蛋
日期:2011-11-17 09:20:52茶鸡蛋
日期:2011-11-10 22:42:38ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15茶鸡蛋
日期:2011-10-24 09:48:48ITPUB十周年纪念徽章
日期:2011-09-27 16:30:47
74#
发表于 2011-10-24 22:37 | 只看该作者
每天坚持一点点,天长日久,滴水穿石,楼主肯定能有大出息~~

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
75#
 楼主| 发表于 2011-10-25 09:36 | 只看该作者

C:\Documents and Settings\Skyman.Man>mysql -h172.16.24.43 -uskyman.man -pmanchungood
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10908873
Server version: 5.5.8-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show engine innodb status\G;
*************************** 1. row ***************************
  Type: InnoDB
  Name:
Status:
=====================================
111025  1:34:01 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 45 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 1258266 1_second, 1257889 sleeps, 125825 10_second, 17 background, 17 flush
srv_master_thread log flush and writes: 1262101
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 1768412, signal count 3322456
Mutex spin waits 170786003, rounds 159137200, OS waits 533095
RW-shared spins 1310647, rounds 26826730, OS waits 746069
RW-excl spins 755764, rounds 18662671, OS waits 399233
Spin rounds per wait: 0.93 mutex, 20.47 RW-shared, 24.69 RW-excl
------------------------
LATEST DETECTED DEADLOCK
------------------------
111012  2:44:44
*** (1) TRANSACTION:
TRANSACTION 9A1B2BE, ACTIVE 44 sec, process no 18205, OS thread id 1087220032 fetching rows
mysql tables in use 3, locked 3
LOCK WAIT 17252 lock struct(s), heap size 1767864, 1861141 row lock(s), undo log entries 6797
MySQL thread id 1279639, query id 43574721 192.168.0.90 skyman.man Sending data
create table test_cpny.fin_metric_data
SELECT dat.*
    FROM cdp.excel_stock es
    inner join web_cdp.fin_metric_data dat
    on (es.stock_id = dat.stock_id)
where es.upd_stmp between '2011-10-12 01:12:22' and '2011-10-12 02:40:21'
  and es.last_pub_excel_id is not null
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1886 page no 30715 n bits 160 index `PRIMARY` of table `cdp`.`fin_metric_data` trx id 9A1B2BE lock mode S waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 26; compact format; info bits 0
0: len 4; hex 000002c9; asc     ;;
1: len 7; hex 3030312e303137; asc 001.017;;
2: len 4; hex 000007d4; asc     ;;
3: len 1; hex 01; asc  ;;
4: len 3; hex 435552; asc CUR;;
5: len 6; hex 000009a1ae16; asc       ;;
6: len 7; hex 6f0000636305f8; asc o  cc  ;;
7: len 4; hex 00000a2f; asc    /;;
8: len 4; hex 0000005d; asc    ];;
9: len 1; hex 08; asc  ;;
10: len 1; hex 01; asc  ;;
11: len 1; hex 01; asc  ;;
12: len 4; hex 0000001b; asc     ;;
13: len 4; hex 00000045; asc    E;;
14: len 1; hex 83; asc  ;;
15: len 3; hex 8fa87f; asc    ;;
16: len 8; hex 5265706f72746564; asc Reported;;
17: len 4; hex 00000001; asc     ;;
18: len 2; hex 5448; asc TH;;
19: len 3; hex 434e59; asc CNY;;
20: len 1; hex 01; asc  ;;
21: len 14; hex 80000000000000026766002ab980; asc         gf *  ;;
22: len 14; hex 8000000000000000000267660118; asc           gf  ;;
23: SQL NULL;
24: len 1; hex 80; asc  ;;
25: len 4; hex 4e94fee8; asc N   ;;

*** (2) TRANSACTION:
TRANSACTION 9A1AE16, ACTIVE 52 sec, process no 18205, OS thread id 1239828800 inserting
mysql tables in use 4, locked 4
1203 lock struct(s), heap size 129464, 83075 row lock(s), undo log entries 180
MySQL thread id 1347644, query id 43572001 172.16.24.42 csfdp Sending data
REPLACE INTO cdp.fin_metric_data (stock_id,metric_cd,prd_year,prd_qtr,accumulate, excel_id,rpt_id,acc_std,biz_cd,acc_cd,row_num,col_num, month_num, bal_sht_dt, rep
fs.prd_year, lcrfs.prd_qtr, lcrfs.accumulate, lcrfs.excel_id,lcrfs.rpt_id,lcrfs.acc_std,lcrfs.biz_cd,lcrfs.acc_cd,lcrfs.row_num,lcrfs.col_num, lcfrp.month_num, lcf
NA' then 2 when 'NM' then 3 else 1 end as data_tp, case lcrfs.data_val when 'NA' then null when 'NM' then null else lcrfs.data_val end as data_val, case lcrfs.data
FROM cdp.listed_cpny_rpt_fin_style_5 lcrfs INNER
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 1886 page no 30715 n bits 160 index `PRIMARY` of table `cdp`.`fin_metric_data` trx id 9A1AE16 lock_mode X locks rec but not gap
Record lock, heap no 2 PHYSICAL RECORD: n_fields 26; compact format; info bits 0
0: len 4; hex 000002c9; asc     ;;
1: len 7; hex 3030312e303137; asc 001.017;;
2: len 4; hex 000007d4; asc     ;;
3: len 1; hex 01; asc  ;;
4: len 3; hex 435552; asc CUR;;
5: len 6; hex 000009a1ae16; asc       ;;
6: len 7; hex 6f0000636305f8; asc o  cc  ;;
7: len 4; hex 00000a2f; asc    /;;
8: len 4; hex 0000005d; asc    ];;
9: len 1; hex 08; asc  ;;
10: len 1; hex 01; asc  ;;
11: len 1; hex 01; asc  ;;
12: len 4; hex 0000001b; asc     ;;
13: len 4; hex 00000045; asc    E;;
14: len 1; hex 83; asc  ;;
15: len 3; hex 8fa87f; asc    ;;
16: len 8; hex 5265706f72746564; asc Reported;;
17: len 4; hex 00000001; asc     ;;
18: len 2; hex 5448; asc TH;;
19: len 3; hex 434e59; asc CNY;;
20: len 1; hex 01; asc  ;;
21: len 14; hex 80000000000000026766002ab980; asc         gf *  ;;
22: len 14; hex 8000000000000000000267660118; asc           gf  ;;
23: SQL NULL;
24: len 1; hex 80; asc  ;;
25: len 4; hex 4e94fee8; asc N   ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1886 page no 36296 n bits 192 index `PRIMARY` of table `cdp`.`fin_metric_data` trx id 9A1AE16 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 26; compact format; info bits 0
0: len 4; hex 000002c9; asc     ;;
1: len 7; hex 3030312e303031; asc 001.001;;
2: len 4; hex 000007d4; asc     ;;
3: len 1; hex 01; asc  ;;
4: len 3; hex 435552; asc CUR;;
5: len 6; hex 000005a9994e; asc      N;;
6: len 7; hex 090002033d0e9f; asc     =  ;;
7: len 4; hex 0000072b; asc    +;;
8: len 4; hex 00000054; asc    T;;
9: len 1; hex 08; asc  ;;
10: len 1; hex 01; asc  ;;
11: len 1; hex 01; asc  ;;
12: len 4; hex 0000001c; asc     ;;
13: len 4; hex 00000045; asc    E;;
14: len 1; hex 83; asc  ;;
15: len 3; hex 8fa87f; asc    ;;
16: len 8; hex 5265706f72746564; asc Reported;;
17: len 4; hex 00000002; asc     ;;
18: len 2; hex 5448; asc TH;;
19: len 3; hex 434e59; asc CNY;;
20: len 1; hex 01; asc  ;;
21: len 14; hex 800000000000001b989204e95300; asc             S ;;
22: len 14; hex 80000000000000000d060e9c01c1; asc               ;;
23: SQL NULL;
24: len 1; hex 80; asc  ;;
25: len 4; hex 4e8afe4e; asc N  N;;

*** WE ROLL BACK TRANSACTION (2)
------------
TRANSACTIONS
------------
Trx id counter C001881
Purge done for trx's n < C001834 undo n < 0
History list length 129
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started, process no 18205, OS thread id 1242491200
MySQL thread id 10908873, query id 292561834 192.168.0.90 skyman.man
show engine innodb status
---TRANSACTION 0, not started, process no 18205, OS thread id 1231042880
MySQL thread id 10909592, query id 292557993 csfdpws.chinascopefinancial.com 172.16.24.41 fdp
---TRANSACTION C001614, not started, process no 18205, OS thread id 1241958720
MySQL thread id 10909330, query id 292542993 172.16.24.42 csfdp
---TRANSACTION 0, not started, process no 18205, OS thread id 1240627520
MySQL thread id 10908466, query id 292500131 csfdpws.chinascopefinancial.com 172.16.24.41 cdp
---TRANSACTION 0, not started, process no 18205, OS thread id 1241692480
MySQL thread id 10908317, query id 292490585 csfdpws.chinascopefinancial.com 172.16.24.41 cdp
---TRANSACTION 0, not started, process no 18205, OS thread id 1237432640
MySQL thread id 10906566, query id 292386323 csfdpws.chinascopefinancial.com 172.16.24.41 cdp
---TRANSACTION BFD0A54, not started, process no 18205, OS thread id 1232640320
MySQL thread id 10873377, query id 292288418 192.168.0.62 sun.shang
---TRANSACTION BFCEF25, not started, process no 18205, OS thread id 1227848000
MySQL thread id 10860886, query id 292543778 hqdb01.chinascopefinancial.com 172.16.24.43 sym
---TRANSACTION BFFFEEC, not started, process no 18205, OS thread id 1241160000
MySQL thread id 10833830, query id 292559054 hqdb01.chinascopefinancial.com 172.16.24.43 sym
---TRANSACTION BFCA0B2, not started, process no 18205, OS thread id 1233439040
MySQL thread id 10826593, query id 292543775 hqdb01.chinascopefinancial.com 172.16.24.43 sym
---TRANSACTION C001876, ACTIVE 0 sec, process no 18205, OS thread id 1241426240 inserting
mysql tables in use 1, locked 1
295 lock struct(s), heap size 31160, 307 row lock(s), undo log entries 307
MySQL thread id 10909671, query id 292561835 csfdpws.chinascopefinancial.com 172.16.24.41 fdp update
replace into reuters_rkd_cr (opinion_orig, opinion_set, xref,
      prod_dt, event_cd, event_asof,
      opinion_meanrating, opinion_meanlabel, opinion_startdate,
      opinion_expir, upd_stmp)
    values ('2011-03-25 04:00:00', 'STD', 200022999,
      '2011-10-22 00:00:00', 'Refresh', '2011-10-21 23:56:40',
      3.1905, 'HOLD', '2011-07-25 14:46:52',
      '2011-03-29 20:00:01', now())
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (read thread)
I/O thread 4 state: waiting for i/o request (read thread)
I/O thread 5 state: waiting for i/o request (read thread)
I/O thread 6 state: waiting for i/o request (write thread)
I/O thread 7 state: waiting for i/o request (write thread)
I/O thread 8 state: waiting for i/o request (write thread)
I/O thread 9 state: waiting for i/o request (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
44331917 OS file reads, 90797626 OS file writes, 1920988 OS fsyncs
0.82 reads/s, 16384 avg bytes/read, 378.06 writes/s, 39.71 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 27452, seg size 27454, 937651 merges
merged operations:
insert 9098534, delete mark 3567904, delete 446221
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 6375023, node heap has 18422 buffer(s)
5416.32 hash searches/s, 124.22 non-hash searches/s
---
LOG
---
Log sequence number 790780341691
Log flushed up to   790780231294
Last checkpoint at  790773317068
0 pending log writes, 0 pending chkp writes
80279090 log i/o's done, 110.18 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 3296722944; in additional pool allocated 0
Dictionary memory allocated 1681691
Buffer pool size   196607
Free buffers       2
Database pages     178182
Old database pages 65761
Modified db pages  12369
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 59635727, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 49117475, created 4146559, written 24304656
0.82 reads/s, 0.00 creates/s, 1198.71 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s
LRU len: 178182, unzip_LRU len: 0
I/O sum[58580]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 18205, id 1195845952, state: sleeping
Number of rows inserted 226886319, updated 412483665, deleted 3081984, read 260362182863
1.20 inserts/s, 2752.98 updates/s, 0.00 deletes/s, 93734.47 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

1 row in set (0.30 sec)

ERROR:
No query specified

mysql>




































































使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
76#
 楼主| 发表于 2011-10-25 09:43 | 只看该作者
本帖最后由 mchdba 于 2011-10-25 09:55 编辑

-- =============================
-- 在线查看mysql innodb存储引擎缓存使用情况
-- =============================

mysql> show engine innodb status\G;
......................
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 3296722944; in additional pool allocated 0
Dictionary memory allocated 1681691
Buffer pool size   196607
Free buffers       2
Database pages     178182
Old database pages 65761
Modified db pages  12369
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 59635727, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 49117475, created 4146559, written 24304656
0.82 reads/s, 0.00 creates/s, 1198.71 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s
LRU len: 178182, unzip_LRU len: 0
I/O sum[58580]:cur[0], unzip sum[0]:cur[0]
--------------

【】我的生产环境内存6G,我分配了3G给mysql 的innodb缓存,在业务低峰起,也就是show full processlist的时候,所以线程都是sleep。那么Free buffers为2。当我在业务高峰期,也就是show full processlist;线程在执行sql语句的时候,我的Free Buffers都为0。
   询问了一个网友刀刀,他们生产环境的内存是64G,给innodb存储引擎缓存分配了35G,在业务低峰期,Free buffers为26G,高峰期不知道是多少,我请他帮忙去查了,等待他的反馈结果,他的是MMM结构,并发峰值在1500左右。

我的个人看法是:我的生产环境的6G的内存已经被完全利用光了,如果可以的话,内存加到12G,应该给数据库服务器加更多的内存,innodb_buffer_pool_size设置成8G,可以让数据库服务器性能提升的更快一些。




使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
77#
 楼主| 发表于 2011-10-25 15:32 | 只看该作者
【转载】http://hi.baidu.com/cavaran/blog/item/2e82b702205ab16b3812bb63.html

在研究innodb_flush_log_at_trx_commit ,google下,看到一篇好文章,share下。

Server A : innodb_flush_log_at_trx_commit = 0
表数据放在sda,普通sas盘。
qavg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.37    0.00    0.37    0.80    0.00   98.45

Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sdb               0.00    56.00    0.00  126.00     0.00  1456.00    11.56     0.17    1.35   0.08   1.00
sda               0.00   857.00    0.00   23.00     0.00  7040.00   306.09     0.17    7.39   4.35  10.00
sdc               0.00   375.00    0.00  137.00     0.00  4096.00    29.90     0.45    3.28   0.07   1.00
dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

Server B : innodb_flush_log_at_trx_commit = 1
表数据放在sda,普通sas盘。可以看到写操作非常频繁,这是因为每一次事务提交或事务外的指令都需要把日志写入(flush)硬盘,这是很费时的。但磁盘性能还能应付。。
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.92    0.00    0.55    5.89    0.00   92.64

Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00   349.00    0.00  173.00     0.00  4152.00    24.00     0.95    5.43   5.38  93.00
sdb               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdc               0.00   166.00    0.00   57.00     0.00  1784.00    31.30     0.00    0.00   0.00   0.00
dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
修改为innodb_flush_log_at_trx_commit = 0 后 写操作次数很明显的降下来了。
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.79    0.00    1.11    0.31    0.00   96.80

Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00   201.00    0.00   11.00     0.00  1696.00   154.18     0.06    5.45   4.55   5.00
sdb               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdc               0.00    90.00    0.00   94.00     0.00  1464.00    15.57     0.00    0.00   0.00   0.00
dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

=========================
innodb_buffer_pool_size
如果用Innodb,那么这是一个重要变量。相对于MyISAM来说,Innodb对于buffer size更敏感。MySIAM可能对于大数据量使用默认的key_buffer_size也还好,但Innodb在大数据量时用默认值就感觉在爬了。 Innodb的缓冲池会缓存数据和索引,所以不需要给系统的缓存留空间,如果只用Innodb,可以把这个值设为内存的70%-80%。和 key_buffer相同,如果数据量比较小也不怎么增加,那么不要把这个值设太高也可以提高内存的使用率。

innodb_additional_pool_size
这个的效果不是很明显,至少是当操作系统能合理分配内存时。但你可能仍需要设成20M或更多一点以看Innodb会分配多少内存做其他用途。

innodb_log_file_size
对于写很多尤其是大数据量时非常重要。要注意,大的文件提供更高的性能,但数据库恢复时会用更多的时间。我一般用64M-512M,具体取决于服务器的空间。

innodb_log_buffer_size
默认值对于多数中等写操作和事务短的运用都是可以的。如果经常做更新或者使用了很多blob数据,应该增大这个值。但太大了也是浪费内存,因为1秒钟总会 flush(这个词的中文怎么说呢?)一次,所以不需要设到超过1秒的需求。8M-16M一般应该够了。小的运用可以设更小一点。

innodb_flush_log_at_trx_commit  (这个很管用)
抱怨Innodb比MyISAM慢 100倍?那么你大概是忘了调整这个值。默认值1的意思是每一次事务提交或事务外的指令都需要把日志写入(flush)硬盘,这是很费时的。特别是使用电池供电缓存(Battery backed up cache)时。设成2对于很多运用,特别是从MyISAM表转过来的是可以的,它的意思是不写入硬盘而是写入系统缓存。日志仍然会每秒flush到硬盘,所以你一般不会丢失超过1-2秒的更新。设成0会更快一点,但安全方面比较差,即使MySQL挂了也可能会丢失事务的数据。而值2只会在整个操作系统挂了时才可能丢数据。

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
78#
 楼主| 发表于 2011-10-25 16:39 | 只看该作者
本帖最后由 mchdba 于 2011-10-25 16:40 编辑

-- ===================================
-- 主主复制模式,一种解决自增的方式
-- ===================================

1.在192.168.0.100的/etc/my.cnf的[mysqld]域后里添加

server_id                = 100
log_bin                  = mysql-bin
log_bin_index            = mysql-bin.index
log_slave_updates        = 1
relay_log                = mysql-relay-bin
relay_log_index          = mysql-relay-bin.index
sync_binlog              = 1
max_binlog_size          = 2000M
auto_increment_increment = 2
auto_increment_offset    = 1
# slave-skip-errors        
2.在192.168.0.200的/etc/my.cnf的[mysqld]域后里添加

server_id                = 200
log_bin                  = mysql-bin
log_bin_index            = mysql-bin.index
log_slave_updates        = 1
relay_log                = mysql-relay-bin
relay_log_index          = mysql-relay-bin.index
sync_binlog              = 1
max_binlog_size          = 2000M
auto_increment_increment = 2
auto_increment_offset    = 2
# slave-skip-errors        = 1062,1053
为了解决我前面提到的同时插入数据时的自增主键冲突问题,我们需要设置
auto_increment_increment 定义AUTO_INCREMENT的步长
auto_increment_offset    定义AUTO_INCREMENT的起点值

为什么在第一个主服务器上面要设置
auto_increment_offset    = 1
而在第二个主服务器上面,却设置成2呢?

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
79#
 楼主| 发表于 2011-10-25 17:36 | 只看该作者
show full processlist里面的 command状态非sleep的线程数.
show status like '%threads%';中 running的线程数.

表明这两种查看方式都可以获取数据库当前在线的用户数量。

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
80#
 楼主| 发表于 2011-10-28 23:03 | 只看该作者
本帖最后由 mchdba 于 2011-10-28 23:03 编辑

-- mysql 连接过多,如何解决。

用root账号登陆进去mysql,就可以查看所有连接了。

如果不是root账号,只要分配process权限,也可以登陆mysql数据库,这个细节我就不知道的。

今天与了几个MySQL高人聊了下,发现自己对一些基本知识点的细节问题还是不太熟悉,只会用,但是不知道为什么这么用?还需要进一步努力之中!

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表