Changeset 1695


Ignore:
Timestamp:
May 26, 2016, 12:13:49 PM (3 years ago)
Author:
jrpelegrina
Message:

Add a function to change sql_mode

Location:
lliurex-sgdb/trunk/fuentes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lliurex-sgdb/trunk/fuentes/debian/changelog

    r1314 r1695  
     1lliurex-sgbd (0.71-lliurex3) xenial; urgency=medium
     2
     3  * Add a function to change sql_mode
     4
     5 -- Juan Ramon Pelegrina <juapesai@hotmail.com>  Thu, 26 May 2016 11:58:30 +0200
     6
    17lliurex-sgbd (0.71-lliurex2) xenial; urgency=medium
    28
  • lliurex-sgdb/trunk/fuentes/install/usr/sbin/lliurex-sgbd

    r1313 r1695  
    1919# --add_include_file -> create include file
    2020# --db_is_present -> check if database exists
     21# --sql_mode -> change sql_mode variable to correct perfomance
    2122###########################################################
    2223
     
    3435
    3536debug=0
     37NOW=$(date +"%Y.%m.%d.%H.%M")
    3638
    3739read_config_file(){
     
    147149                mkdir -p $BACKUP_PATH
    148150        fi
    149         NOW=$(date +"%Y.%m.%d.%H.%M")   
     151        #NOW=$(date +"%Y.%m.%d.%H.%M") 
    150152        echo "Doing database backup: $BACKUP_PATH/backup.$NOW.sql"
    151153        mysqldump -u root -p$MYSQL_ROOT_PASS $DB_NAME > $BACKUP_PATH"/backup."$NOW".sql" 2>/dev/null
     
    229231}
    230232
     233edit_sql_mode(){
     234        MYSQLCNF_PATH="/etc/mysql/mysql.cnf"
     235        MYSQLCNF_DIR=$(dirname ${MYSQLCNF_PATH})
     236        SQLCONFIG_NEW='sql_mode="NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'
     237
     238    if [ -f ${MYSQLCNF_PATH}  ]; then
     239        SQLCONFIG_OLD=$(sed -e '/sql_mode'/!d ${MYSQLCNF_PATH})
     240       
     241        if [ -z ${SQLCONFIG_OLD} ]; then
     242
     243                echo "Doing backup of file ${MYSQLCNF_PATH}"
     244                cp ${MYSQLCNF_PATH} ${MYSQLCNF_DIR}"/mysql_"${NOW}".cnf"
     245                echo "Adding sql_mode in file ${MYSQLCNF_PATH}"
     246                sed -i '$a'${SQLCONFIG_NEW} ${MYSQLCNF_PATH}
     247            systemctl restart mysql
     248        else
     249                if [[ ${SQLCONFIG_OLD} == ${SQLCONFIG_NEW} ]]; then
     250
     251                        echo "NOTHING TO DO. File ${MYSQLCNF_PATH} already update"
     252                else
     253                        echo "Doing backup of file ${MYSQLCNF_PATH}"
     254                        cp ${MYSQLCNF_PATH} ${MYSQLCNF_DIR}"/mysql_"${NOW}".cnf"
     255                        echo "Adding new sql_mode configuration in file ${MYSQLCNF_PATH}"
     256                        sed -i 's/'${SQLCONFIG_OLD}'/'${SQLCONFIG_NEW}'/g' ${MYSQLCNF_PATH}
     257                        systemctl restart mysql
     258                fi             
     259        fi
     260    else
     261        echo "NOTHING TO DO. File ${MYSQLCNF_PATH} NOT FOUND"   
     262    fi 
     263}
     264
    231265usage (){
    232         echo "usage:  lliurex-sgbd --config package_name | --template package_name | --install package_name  | --upgrade package_name | --remove package_name | --purge package_name | --inject_sql package_name sql_file_with_path | --db_is_present package_name | --add_include_file package_name | --is_include_present package_name "
     266        echo "usage:  lliurex-sgbd --config package_name | --template package_name | --install package_name  | --upgrade package_name | --remove package_name | --purge package_name | --inject_sql package_name sql_file_with_path | --db_is_present package_name | --add_include_file package_name | --is_include_present package_name | --sql_mode package_name"
    233267}
    234268
     
    330364        ;;
    331365
     366        --sql_mode)
     367                edit_sql_mode
     368        ;;     
     369
    332370        *)
    333371                usage
Note: See TracChangeset for help on using the changeset viewer.