MariaDB SHOW,ANALYZE,CHECK

MariaDB SHOW,ANALYZE,CHECK

jlive@MacBook-Pro:mariadb_scripts $mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 71

Server version: 5.5.5-10.1.10-MariaDB-log MariaDB Server


Copyright (c) 2000, 2015, 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.


(jlive)[(none)]>SHOW DATABASES;

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

| Database           |

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

| crashcourse        |

| information_schema |

| mysql              |

| performance_schema |

| phpmyadmin         |

| zabbix             |

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

6 rows in set (0.00 sec)


(jlive)[(none)]>DROP DATABASE crashcourse;

Query OK, 14 rows affected (0.03 sec)


(jlive)[(none)]>CREATE DATABASE crashcourse;

Query OK, 1 row affected (0.00 sec)


(jlive)[(none)]>USE crashcourse;

Database changed

(jlive)[crashcourse]>SOURCE ./create.sql

Query OK, 0 rows affected (0.00 sec)


Query OK, 0 rows affected (0.01 sec)


Query OK, 0 rows affected (0.00 sec)


(jlive)[crashcourse]>SOURCE ./populate.sql

Query OK, 1 row affected (0.00 sec)


Query OK, 1 row affected (0.00 sec)


Query OK, 1 row affected (0.00 sec)


 

Query OK, 1 row affected (0.00 sec)


(jlive)[crashcourse]>SHOW TABLES;

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

| Tables_in_crashcourse |

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

| customers             |

| orderitems            |

| orders                |

| productnotes          |

| products              |

| vendors               |

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

 

6 rows in set (0.01 sec)

(jlive)[crashcourse]>SHOW CREATE DATABASE crashcourse;

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

| Database    | Create Database                                                      |

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

| crashcourse | CREATE DATABASE `crashcourse` |

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

1 row in set (0.00 sec)


(jlive)[crashcourse]>SHOW GRANTS;

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

| Grants for jlive@%                                                                                                              |

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

| GRANT ALL PRIVILEGES ON *.* TO 'jlive'@'%' IDENTIFIED BY PASSWORD '*C15A2384C61922FBA3DA581D4AD9FF66EA0BEEB3' WITH GRANT OPTION |

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

 

1 row in set (0.00 sec)


(jlive)[crashcourse]>SHOW ERRORS;

Empty set (0.00 sec)


(jlive)[crashcourse]>SHOW WARNINGS;

Empty set (0.00 sec)

(jlive)[crashcourse]>SHOW PROCESSLIST;

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

| Id | User   | Host                | db          | Command | Time | State | Info             | Progress |

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

4 | zabbix | localhost           | zabbix      | Sleep   |   13 |       | NULL               0.000 |

5 | zabbix | localhost           | zabbix      | Sleep     2 |       | NULL               0.000 |

6 | zabbix | localhost           | zabbix      | Sleep   |   35 |       | NULL               0.000 |

7 | zabbix | localhost           | zabbix      | Sleep   |   31 |       | NULL               0.000 |

8 | zabbix | localhost           | zabbix      | Sleep     3 |       | NULL               0.000 |

9 | zabbix | localhost           | zabbix      | Sleep     0 |       | NULL               0.000 |

| 10 | zabbix | localhost           | zabbix      | Sleep     8 |       | NULL               0.000 |

| 13 | zabbix | localhost           | zabbix      | Sleep   |   29 |       | NULL               0.000 |

| 14 | zabbix | localhost           | zabbix      | Sleep   |   28 |       | NULL               0.000 |

| 15 | zabbix | localhost           | zabbix      | Sleep   |   23 |       | NULL               0.000 |

| 17 | zabbix | localhost           | zabbix      | Sleep   |   19 |       | NULL               0.000 |

| 18 | zabbix | localhost           | zabbix      | Sleep   | 3102 |       | NULL               0.000 |

| 23 | zabbix | localhost           | zabbix      | Sleep   942 |       | NULL               0.000 |

| 62 | zabbix | localhost           | zabbix      | Sleep   822 |       | NULL               0.000 |

| 66 | zabbix | localhost           | zabbix      | Sleep   704 |       | NULL               0.000 |

| 67 | zabbix | localhost           | zabbix      | Sleep   703 |       | NULL               0.000 |

| 68 | zabbix | localhost           | zabbix      | Sleep   102 |       | NULL               0.000 |

| 71 | jlive  | 192.168.130.1:52238 | crashcourse | Query     0 | init  | SHOW PROCESSLIST |    0.000 |

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

 

18 rows in set (0.00 sec)


SHOW STATUS;

SHOW CREATE TABLE orders;



ANALYZE,CHECK也可以查看相关信息

(jlive)[crashcourse]>ANALYZE TABLE orders;

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

| Table              | Op      | Msg_type | Msg_text |

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

| crashcourse.orders | analyze | status   | OK       |

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

1 row in set (0.00 sec)


(jlive)[crashcourse]>CHECK TABLE orders, orderitems;

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

| Table                  | Op    | Msg_type | Msg_text |

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

| crashcourse.orders     | check | status   | OK       |

| crashcourse.orderitems | check | status   | OK       |

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

 

2 rows in set (0.00 sec)




显示执行进度--变量progress_report_time

默认为每5秒刷新一次执行进度,取值范围为1-5,单位秒,当取值为0时就禁用了progress report

mytop脚本提供了更丰富的功能


MariaDB [(none)]> SHOW VARIABLES LIKE 'progress_report_time';

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

| Variable_name        | Value |

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

| progress_report_time | 5     |

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

1 row in set (0.00 sec)


MariaDB [(none)]> SET progress_report_time = 0;

Query OK, 0 rows affected (0.00 sec)

MariaDB [crashcourse]> ALTER TABLE products engine=myisam;

Query OK, 14 rows affected (0.01 sec)

Records: 14  Duplicates: 0  Warnings: 0



定期check,repair,tunning数据库

1.创建系统用户sysuser

root@jlive:~#useradd -r -m sysuser -s /sbin/nologin 

2.创建数据库用户maint并赋予SELECT,INSERT权限

GRANT SELECT,INSERT ON *.* TO maint IDENTIFIED BY 'maintuserpassword';

3.在系统用户sysuer家目录创建用户级的.my.cnf

root@jlive:~#cat >/home/sysuser/.my.cnf <<HERE

[client]

user = maint

password = maintuserpassword

HERE

root@jlive:~#chmod 600 /home/sysuser/.my.cnf 

4.创建计划任务

 

root@jlive:~#cat >/etc/cron.d/mariadb <<HERE

15 23 * * 1   sysuser /usr/bin/mysqlcheck -A --auto-repair

15 23 * * 2-7 sysuser /usr/bin/mysqlcheck -A --optimize

HERE

posted @ 2016-03-18 22:34  李庆喜  阅读(338)  评论(0编辑  收藏  举报