Mysql数据库备份脚本(使用mysqldump)

Mysql(mysqldump)备份脚本 记录下服务器上一个备份 mysql 数据库的脚本,使用 mysql 自带的mysqldump命令 !/usr/bin/env bash USER=username PASSWORD=password MAXIMUM_BACKUP_FILES=10 BACKUP_FOLDER=/path/to/save/folder DATABASES=( db_name_0 db_name_1 ) # check mysqldump instlled _=$(command -v mysqldump) if [[ $? != 0 ]] then printf "You don't seem to mysqldump installed, exit..\n" exit 1 fi # create backup folder if [ ! -d $BACKUP_FOLDER ] then mkdir $BACKUP_FOLDER fi # backup for DB in ${DATABASES[@]} do echo backing up ${DB} database ... if $(mysqldump --host=localhost --user=${USER} --password=${PASSWORD} ${DB} | gzip -9 > ${BACKUP_FOLDER}/db_${DB}_$(date +"%Y%m%d")....

November 8, 2018 · 2 min · 260 words · Fython

Mariadb Mysql 字符集设置

Mariadb Mysql Character Sets and Collations MariaDB数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可。开发这个分支的原因之一是:甲骨文公司收购了 MySQL 后,有将 MySQL 闭源的潜在风险,因此社区采用分支的方式来避开这个风险。 所以说mariadb完全兼容mysql的设置,完全可以用mariadb代替mysql。 初次安装完 mariadb 后运行mysql_secure_installation 本人centos7编辑/etc/my.cnf添加如下配置(utf8mb4支持 4 个字节的emoji表情完全兼容utf8,当然也可以换成utf8不使用表情) [mysqld] init_connect='SET collation_connection = utf8mb4_unicode_ci' init_connect='SET NAMES utf8mb4' skip-character-set-client-handshake # 服务端默认字符集 character-set-server=utf8mb4 # 连接层默认字符集 collation-server=utf8mb4_unicode_ci [client] # 客户端来源数据默认字符集 default-character-set=utf8mb4 [mysql] # 客户端来源数据默认字符集 default-character-set=utf8mb4 重启 mariadb 服务,运行systemctl restart marriadb.service 登录后show variables like '%char%'和show variables like '%collation%'查看是否和如下相同。 MariaDB [(none)]> show global variables like '%char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0....

March 18, 2017 · 1 min · 154 words · Fython