Tag Archive มายเอสคิวเอล

Byphunsanit

MySql: Basic Config โดย MySQLTuner

เว็บบน DigitalOcean มันชอบบอกว่า monitoring resolved: Memory Utilization is running high กับ NAS server ที่บ้าน ram แค่ 1 GB มันต๊อแต๊ อยากจะสลบอยู่ตลอด เลยต้อง configuration เพิ่มประสิทธิภาพใหม่ให้มันทำงานได้ โดยใช้ MySQLTuner ที่จะช่วยปรับแต่ง database server ได้หลายตัวทั้ง Galera, MariaDB, MySQL, Percona

  1. ก่อนอื่นก็ download MySQLTuner มาช่วยตรวจสอบการติดตั้งที่เหมาะสมก่อนโดยใช้ command
    wget http://mysqltuner.pl/ -O mysqltuner.pl
  2. เรียกใช้โดย
    perl mysqltuner.pl
    จะเห็นข้อความที่จะต้องใช้ในการปรับแต่ง MySql หรือดาต้าเบสตัวอื่น ๆ โดยให้ดูบรรทัดที่ขึ้นต้นด้วย [!!] เป็นหลัก
  3. แก้มายเอสคิวเอล และเทสโดยคำสั้ง
    mysqld –validate-config
    sudo systemctl restart mysql.service
    perl mysqltuner.pl
    วนไปจนกว่าจะได้ performance ที่พอใจ
  4. ตัวอย่างไฟล์ config ที่ได้สำหรับ NAS ที่มี ram 1 GB
    #
    # The MySQL database server configuration file.
    #
    # You can copy this to one of:
    # - "/etc/mysql/my.cnf" to set global options,
    # - "~/.my.cnf" to set user-specific options.
    #
    # One can use all long options that the program supports.
    # Run program with --help to get a list of available options and with
    # --print-defaults to see which it would actually understand and use.
    #
    # For explanations see
    # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
    
    #
    # * IMPORTANT: Additional settings that can override those from this file!
    #   The files must end with '.cnf', otherwise they'll be ignored.
    #
    
    !includedir /etc/mysql/conf.d/
    !includedir /etc/mysql/mysql.conf.d/
    
    #test by mysqltuner
    
    [mysqld]
    # Skip reverse DNS lookup of clients.
    # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_skip_name_resolve
    skip-name-resolve
    
    # Ratio InnoDB redo log capacity / InnoDB Buffer pool size should be equal to 25%.
    #https://dev.mysql.com/doc/refman/8.0/en/innodb-buffer-pool-resize.html
    #of RAM but beware of setting memory usage too high
    innodb_buffer_pool_size=300M
    
    #https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_connections
    max_connections=70

นอกจากนี้ คำสั่ง perl mysqltuner.pl ยังสามารถใช้ options เพิ่มเติมได้อีกเช่น

optionsความหมายค่าเริ่มต้นตัวอย่างชนิดตัวแปร
–debugdebugging information
–dumpdirexport to–dumpdir=./resultfile path
–forcememแรมทั้งหมด1024–forcemem 32768megabytes
–forceswapswap memory–forceswap 16384megabytes
–hostremote serverlocalhost–host 127.0.0.1IP
–jsonออกรายงานเป็น JSON–json > reports.jsonfile path
–outputfileออกรายงานเป็นไฟล์–outputfile /tmp/result_mysqltuner.txtfile path
–pass, –passwordรหัสผ่าน–pass admin_passwordstring
–portport3306–port 3306int
–socketใช้ socket ต่างออกไปสำหรับ localhost
–userusername–user admin_userstring
–verboseรายละเอียด–verbose
options บางส่วนที่สามารถใช้ได้

อ่านเพิ่มเติม