Category Archive Programming

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 3306 int
–socketใช้ socket ต่างออกไปสำหรับ localhost
–userusername–user admin_userstring
–verboseรายละเอียด–verbose
options บางส่วนที่สามารถใช้ได้

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

Byphunsanit

PHP: 8.3 บน Ubuntu 23.10.1 แล้ว Error

ลง PHP 8.3 ตัวใหม่น่าสุด ลงบนอูบุนตู 23.10 ตัวใหม่เหมือนกันแต่กลับเจอเอ้อเร้อ php8.3-intl : Depends: libicu70 (>= 70.1-1~) but it is not installable

  1. เข้าไปที่ terminal
  2. ไปแก้ sources.list โดยใช้คำสั่ง
    sudo nano /etc/apt/sources.list
    แล้วเพิ่มไปอีก 1 บรรทัด
    deb http://archive.ubuntu.com/ubuntu/ jammy-proposed main
    แล้ว save โดน CTRL+X และ Y
  3. update package index โดย
    sudo apt-get update
  4. ติดตั้ง libicu70 โดย
    sudo apt-get install libicu70
  5. ทดสอบลง PHP 8.3 โดยใช้ extension ตามที่ WordPress แนะนำ เช่น
    sudo apt-get install php8.3-{bcmath,cgi,cli,common,curl,fpm,gd,gettext,imagick,intl,mbstring,mysql,opcache,soap,xml,xmlrpc,xsl,zip}
  6. enable ให้ใช้บน Apache ได้โดยคำสั่ง
    sudo a2enmod php8.3

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

Byphunsanit

Flutter: One or more plugins require a higher Android SDK version error occurs when i run the project

เจอกับ error แบบนี้ One or more plugins require a higher Android SDK version. Fix this issue by adding the following to C:\Users\…\app\build.gradle: android { compileSdkVersion 33 … }

แก้โดยเปิดไฟล์ตาม path ที่เห็นแล้วก็แก้ compileSdkVersion เป็น version ที่เห็นดูก็ใช้ได้

Cr. One or more plugins require a higher Android SDK version error occurs when i run the project

Byphunsanit

Flutter: error unable to find git in your path

ถ้า run flutter doctor -v หรือ flutter pub get แล้วขึ้น error unable to find git in your path แก้ได้โดย

  1. เปิด Windows PowerShell โดยใช้สิทธิ์ administrator
  2. cd ไป folder ที่เก็บงาน เช่น C:\UsersGit\app_develop
  3. git config –global –add safe.directory “C:\UsersGit\app_develop”

จากนั้นทดสอบโดยใช้ flutter doctor -v ได้ตามปกติ

cr: How to solve “Unable to find git in your PATH” on Flutter?

Byphunsanit

Node.js: cannot be loaded because running scripts is disabled on this system

ถ้า PowerShell run TypeScript, Node.js หรือ run tsc –version แล้วมี error ประมาณ
tsc : File C:\Users\pitt\AppData\Roaming\npm\tsc.ps1 cannot be loaded because running scripts is disabled on this system. For more information,
see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

แก้ได้โดยใช้ command โดยสิทธิ์ Administrator

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

โดยสามารดูคำสั่งเพิ่มเติมได้จาก about_Execution_Policies

cr: PowerShell bug “execution of scripts is disabled on this system.”