DB Maintenance

    版本為 22:15, 3 Oct 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    Tablespace Shrink

    資料表刪除大量的歷史資料列後,所屬的 Tablespace 檔案大小不會自動變小,必須執行維護指令

    mysql> OPTIMIZE table foo;
    

    一次優化所有的資料表

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)

    Mariadb log 管理維護

    手動清除

    $> cat /dev/null > /var/log/mysql.log
    $> mysqladmin -uroot -p flush-logs
    

    使用 logrotate 服務自動管理
    1. 新增 /etc/logrotate.d/mariadb:

    /var/log/mariadb/mariadb.log {
        create 640 mysql mysql
        notifempty
        daily
        rotate 3
        missingok
        compress
        postrotate
            # just if mysqld is really running
            if test -x /usr/bin/mysqladmin && \
                /usr/bin/mysqladmin ping &>/dev/null
            then
                /usr/bin/mysqladmin flush-logs
            fi
        endscript
    }
    

    2. 新增 mysql 管理帳號密碼檔

    $> vi ~/.my.cnf
    
    [mysqladmin]
    user            = root
    password        = YourPass
    
    $> chmod 0600 ~/.my.cnf 
    
    Powered by MindTouch Core