天天看點

面對一個全新的環境,作為一個Mysql DBA,應該了解

2009年07月08日 作者: 大頭剛 

    前段時間有高人寫了一篇《面對一個全新的環境,作為一個Oracle DBA,首先應該了解什麼》,本文借花獻佛,總結了一些思路,如何面對一個全新的Mysql環境。

1、先要了解目前的Mysql資料庫的版本和平台以及字元集等相關資訊

mysql> status

--------------

mysql  Ver 14.14 Distrib 5.1.34, for unknown-linux-gnu (x86_64) using  EditLine wrapper

Connection id:                25874330

Current database:      

Current user:              

SSL:                        Not in use

Current pager:                stdout

Using outfile:                ''

Using delimiter:        ;

Server version:                5.1.34-log Source distribution

Protocol version:        10

Connection:                Localhost via UNIX socket

Server characterset:        utf8

Db     characterset:        utf8

Client characterset:        utf8

Conn.  characterset:        utf8

UNIX socket:                /tmp/mysql.sock

Uptime:                        13 days 14 hours 18 min 36 sec

Threads: 7  Questions: 190708290  Slow queries: 19  Opens: 57835  Flush tables: 1

Open tables: 84  Queries per second avg: 162.344

2、其次要了解你的資料庫中支援哪些存儲引擎,5.1的話順便查下插件情況。

mysql> show engines;

+------------+---------+----------------------------------------------------------------+--------------+------+------------+

| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |

| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |

| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |

| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |

| CSV        | YES     | CSV storage engine                                             | NO           | NO   | NO         |

| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |

| FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |

| ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |

| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance         | NO           | NO   | NO         |

8 rows in set (0.00 sec)

mysql> show plugins;

+------------+----------+----------------+---------+---------+

| Name       | Status   | Type           | Library | License |

| binlog     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| partition  | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| ARCHIVE    | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| BLACKHOLE  | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| CSV        | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| FEDERATED  | DISABLED | STORAGE ENGINE | NULL    | GPL     |

| MEMORY     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| InnoDB     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| MyISAM     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

| MRG_MYISAM | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |

#show binlog events;  檢視binlog

3、搞清楚這個環境是單機還是叢集?

mysql> show variables like 'have_ndbcluster';

+-----------------+-------+

| Variable_name   | Value |

| have_ndbcluster | NO    |

1 row in set (0.00 sec)

4、是否配置了REPLICATION?

show slave status\G;

show master status\G;

5、檢視Mysql的日志模式,檢視近期的慢查詢日志和ERR日志。

mysql> show variables like 'log%';

+---------------------------------+----------------------+

| Variable_name                   | Value                |

| log                             | OFF                  |

| log_bin                         | ON                   |

| log_bin_trust_function_creators | OFF                  |

| log_bin_trust_routine_creators  | OFF                  |

| log_error                       | /dir/hostname.err    |

| log_output                      | FILE                 |

| log_queries_not_using_indexes   | OFF                  |

| log_slave_updates               | OFF                  |

| log_slow_queries                | ON                   |

| log_warnings                    | 1                    |

 

6、檢視Mysql目前有哪些觸發器和存儲過程

mysql> show triggers;

mysql> show procedure status;

7、是否支援分區,如果支援哪些使用了分區表

mysql> show variables like 'have_part%';

+-------------------+-------+

| Variable_name     | Value |

| have_partitioning | YES   |

mysql> select TABLE_NAME from information_schema.PARTITIONS where PARTITION_NAME is not null;

8、有多少使用者擁有超級權限,是否有密碼為空(ROOT密碼預設為空),密碼為空馬上處理。

mysql> select * from information_schema.USER_PRIVILEGES where PRIVILEGE_TYPE='SUPER';

mysql> select host,User,Password from mysql.user where Password='';

+-------------+------+----------+

| host        | User | Password |

| localhost   | root |          |

| 127.0.0.1   | root |          |

mysql> delete from mysql.user where Password='';flush PRIVILEGES;

9.show processlist

執行一會show processlist,看看 Mysql 能有多少并發,一般都是什麼sql。

10、更進一步,Mysql的備份方法和政策是什麼?網絡環境的配置是如何的?

11、跑幾個性能分析報告,看看最近系統的運作狀态如何,例如用mysqlreport。

OK,以上資訊基本上對你新接觸的這個系統有了一個大概的了解,接下來你再慢慢的深入分析,然後制訂出一套符合實際情況的運維規範來。