MySQL常用shell脚本
2023-09-11 14:16:16 时间
- Rename database 重命名数据库
#!/bin/env bash echo -e "\e[5mthe program is designed to rename database!\e[0m" read -p 'the source database: ' src read -p 'the destination database: ' dst echo -e "the source database: \e[7m$src\e[0m the destination datatabase: \e[7m$dst\e[0m do you want to continue? yes/no" read opt echo $opt if [[ $opt == "yes" ]];then mysql -e "create database if not exists $dst default character set utf8mb4 collate utf8mb4_general_ci" mysql --skip-column-names -e "select table_name from information_schema.tables where table_schema=\"$src\"" |\ while read b;do printf 'rename \e[7m%-50s\e[0m to \e[7m%-50s\e[0m' $src.$b $dst.$b echo mysql -e "rename table $src.$b to $dst.$b" done fi mysql -e "drop database $src"
- 批量重命名 character set & collation
#!/bin/bash host=172.16.10.200 user=root password='arbitrary0!' declare -a database database=(CJML_QxbEPC) function bacula() { #echo $1 mysql -h"$host" -u$user --password=$password --skip-column-names -e "show full tables from $1 where table_type = 'BASE TABLE'" 2>/dev/null | awk '{print $1}' | while read b;do #echo $b #echo -e database $1 '\t\t' table "\e[7m$b\e[0m" '\t\t'convert to character set utf8mb4 collation utf8mb4_general_ci printf '%s \e[5m%-15s\e[0m %s \e[7m%-30s\e[0m %s' database $1 table $b 'convert to character set utf8mb4 collation utf8mb4_general_ci' echo mysql -h$host -u$user --password=$password -e "set @@session.foreign_key_checks=0;alter table ${1}.$b convert to character set utf8mb4 collate utf8mb4_general_ci" 2>/dev/null; done } function main() { for b in ${database[@]};do bacula $b done } main
相关文章
- MySQL性能优化的最佳20+条经验
- 【Mysql 学习】mysql 字符集
- 设置MySQL数据库名不区分大小写
- 【MySql】mysql 表的常规管理
- shell安装mysql,连接数据库,创建数据库
- MySQL配置文件mysql.ini参数详解、MySQL性能优化
- MySQL锁详解
- Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on linux
- 数据库内核月报 - 2015 / 08-MySQL · 功能分析 · MySQL表定义缓存
- MYSQL随机抽取查询 MySQL Order By Rand()效率问题
- Mysql索引数据结构有多个选择,为什么一定要是B+树呢?_面试 (MySQL 索引为啥要选择 B+ 树)
- Mysql 如果有多个可选条件怎么加索引_MySQL|mysql-索引
- Linux重置Mysql密码_解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost
- mysql的delete truncate drop说明 mysql删除外键 mysql删除索引 mysql查询外键key_column_usage mysql查询索引tatistics
- MySQL Study之--Mysql无法启动“mysql.host”
- zabbix监控mysql
- 21.第六章 Shell脚本编程基础入门-- shell 脚本语言的基本用法(四)
- Shell脚本运行hive语句 | hive以日期建立分区表 | linux schedule程序 | sed替换文件字符串 | shell推断hdfs文件文件夹是否存在
- mysql 查看 脏页_MySQL:刷脏页
- Mysql中的事务
- mysql主从同步配置详解