HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vps-320ddf0a 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: lamphim (1008)
PHP: 7.4.3-4ubuntu2.29
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/share/fastpanel2/bin/mysql/shared-functions.sh
#!/bin/bash

function GenerateMysqlPassword {
    if [ ! -f /root/.my.cnf ]; then
        Debug "Generating password with pwgen."
        MYSQL_PASSWORD=`pwgen 16 1` || InstallationFailed
        echo -e "[client]\nuser = root\npassword = ${MYSQL_PASSWORD}\n" > /root/.my.cnf
    else
        Warning "File /root/.my.cnf exists. Checking MySQL installation."
        
    fi
}

function MySQLSecureInstallation {
    mysql --defaults-file=/root/.my.cnf -e "DELETE FROM mysql.user WHERE User='';"
    mysql --defaults-file=/root/.my.cnf -e "drop database IF EXISTS test"
    mysql --defaults-file=/root/.my.cnf -e "delete from mysql.db where db='test' or db='test\_%'"
}

function SetRecommenedSettingsMySQL_8_0 {
    if [ -f /etc/mysql/my.cnf ]; then
        echo '!include /etc/mysql/my.cnf.fastpanel/99-fastpanel.cnf' >> /etc/mysql/my.cnf || InstallationFailed
    fi
    mkdir -p /etc/mysql/my.cnf.fastpanel/
    cat << EOF > /etc/mysql/my.cnf.fastpanel/99-fastpanel.cnf
[mysqld]
disable-log-bin
innodb-buffer-pool-size=128M
innodb-flush-log-at-trx-commit=2
innodb-flush-method=O_DIRECT
max-heap-table-size=32M
sql-mode=
tmp-table-size=32M
transaction-isolation=READ-COMMITTED
default-authentication-plugin=mysql_native_password
mysqlx=OFF
performance-schema=OFF
EOF
    RestartMySQL
}

function SetRecommenedSettingsMySQL {
    if [ -f /etc/mysql/my.cnf ]; then
        echo '!include /etc/mysql/my.cnf.fastpanel/99-fastpanel.cnf' >> /etc/mysql/my.cnf || InstallationFailed
    fi
    mkdir -p /etc/mysql/my.cnf.fastpanel/
    cat << EOF > /etc/mysql/my.cnf.fastpanel/99-fastpanel.cnf
[mysqld]
innodb-buffer-pool-size=128M
innodb-flush-log-at-trx-commit=2
innodb-flush-method=O_DIRECT
max-heap-table-size=32M
query-cache-limit=16M
query-cache-size=64M
query-cache-type=ON
sql-mode=
tmp-table-size=32M
transaction-isolation=READ-COMMITTED
performance-schema=OFF
EOF
    RestartMySQL
}

function RestartMySQL {
    if [ -f /lib/systemd/system/mysql.service ]; then
        systemctl restart mysql.service || InstallationFailed
    elif [ -f /lib/systemd/system/mariadb.service ]; then
        systemctl restart mariadb.service || InstallationFailed
    elif [ -f /etc/init.d/mysql ]; then
        /etc/init.d/mysql restart || InstallationFailed
    fi
}