`

Clone user / Dump views in MySQL

 
阅读更多

 
   Clone user / Dump views in MySQL

 

 

1. 数据库搬迁或复制的时候,需要同步MySQL user 及其权限,创建了脚本操作,如下:

 

 

#!/bin/bash -l
if [ $# -lt 1 ]; then
    echo "usage: $0 [MySQLHost]"                                                                      
    exit 1
fi
MySQLHost=${1}
MySQLbin="`which mysql`"
if [ ! -f "${MySQLbin}" ]; then
        MySQLbin="/usr/local/mysql/bin/mysql"
fi

if [ ! -f "${MySQLbin}" ]; then
  echo "can't find the mysql command,please check"                                                                      
  exit 1
fi
echo "SELECT DISTINCT CONCAT (\"show grants for '\", user, \"'@'\", host, \"';\") AS query FROM mysql.user where user not in ('root','mysql') and trim(ifnull(user,''))!=''; " >   script.sql
read -s -p "Enter the mysql password: "

if [ "$REPLY" == "" ]; then
  echo "no password typed, the program will exit"
  exit 1
fi

"${MySQLbin}" -h"${MySQLHost}" -umysql -p"${REPLY}"  < script.sql > output.sql ;
cat output.sql | grep show > output1.sql  ; rm output.sql -f ;
output_file="grants_for_mysql_account_on_${1}.sql"
"${MySQLbin}"  -h"${MySQLHost}"  -umysql -p"${REPLY}"  < output1.sql > ${output_file} ;
clear
echo "-----Exported Grants-----"
sed -i 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' "${output_file}"
cat  "${output_file}"  ; rm  output1.sql -f
echo "-------------------------"
echo "generated ${output_file}"
rm  script.sql -f

 

 

 2. 有时候,只需要备份或导出并搬迁一个数据库的所有 View,

可用命令如下:

mysql INFORMATION_SCHEMA --skip-column-names --batch -e "select table_name from tables where table_type = 'VIEW' and table_schema = 'db'" | xargs mysqldump db > /tmp/views_db.sql

 

0
0
分享到:
评论

相关推荐

    rtmpdump 2.4

    git clone git://git.ffmpeg.org/rtmpdump That will get you the very latest code. If you're looking for a specific older release you can look under: svn://svn.mplayerhq.hu/rtmpdump/tags The latest ...

    templatious:通用C ++ 11通用库Templatious。 http

    mkdir /home/theuser/Templatious-Clone cd /home/theuser/Templatious-Clone git clone https://github.com/davidkazlauskas/templatious.git 然后,在您最喜欢的C ++构建系统上,添加include目录(例如cmake) ...

    gitget:fast快速轻松地克隆GitHub存储库

    # (downloads the default branch of user/repo from GitHub) $ npx gitget user/repo # clone to /folder $ npx gitget user/repo folder # clone subfolder to /folder $ npx gitget user/repo/subfolder folder #...

    build-a-molecule:“构建分子”是PhET Interactive Simulations在HTML5中进行的教育模拟

    快速开始(1)克隆仿真及其依赖项: git clone https://github.com/phetsims/assert.gitgit clone https://github.com/phetsims/axon.gitgit clone https://github.com/phetsims/babel.gitgit clone ...

    mysql8.0.23+ 主从配置

    [root@master ~]# xtrabackup --defaults-file=/u01/mysql3308/my.cnf --user=xtrabk --password=xtrabk --socket=/u01/mysql3308/data/mysql.sock --backup --target-dir=/u01/mysql3308/backup/full/ ``` 然后,...

    彻底解决Mac端git clone/push速度太慢的问题

    彻底解决Mac端git clone/push速度太慢的问题,详情请参阅文档。

    mysql-colorize:为mysql表添加颜色

    mysql-colorize mysql的着色安装重击例如,将存储~/.bash/mysql-colorize到~/.bash/mysql-colorize git clone https://github.com/horosgrisa/mysql-colorize.bash ~ /.bash/mysql-colorize 之后是mysql-colorize....

    FreeBSD11下安装MySQL数据库

    sudo /usr/local/mysql/bin/mysqld_install_db --user=mysql ``` **六、配置系统服务** 配置MySQL为系统服务,使其在启动时自动启动。编辑`/etc/rc.conf`文件,添加以下行: ``` mysql_enable="YES" ``` **七、...

    mysql源码安装编译

    git clone https://github.com/mysql/mysql-server.git ``` 进入源代码目录后,创建一个构建目录,并进入该目录: ```bash cd mysql-server mkdir build cd build ``` 然后使用CMake配置编译过程。这里我们可以...

    Clone Detection in Secure Messaging- Improving Post-Compromise

    Clone Detection in Secure Messaging- Improving Post-Compromise Security in Practice

    tiktok-clone:使用React Native克隆TikTok应用程序布局

    从您的命令行: # Clone this repository$ git clone https://github.com/matheuscastroweb/tiktok-clonetiktok-clone# Go into the repository$ cd tiktok-clone# Install dependencies$ yarn install# Run

    ubuntu使用git clone克隆/下载github模型速度慢的解决方案

    使用在linux操作系统上使用git clone下载github上模型速度慢,多数是因为网不好。 提供了两种方法,可以同时使用。 方法:先刷hosts 1. 命令行输入下列代码,找到 github.global.ssl.fastly.Net对应的Address,记录 ...

    mysql-build:编译并安装MySQL

    安装git clone git://github.com/kamipo/mysql-build.git ~/mysql-buildexport PATH="$HOME/mysql-build/bin:$PATH"用法mkdir -p ~/opt/mysqlmysql-build -v 5.7.10 ~/opt/mysql/mysql-5.7.10cd ~/opt/mysql/mysql-...

    一套读取、执行、备份及生成回滚语句的一整套MySQL运维工具.zip

    开始 [英文] [中文]goInception 是一款 MySQL 维护...文档 [文档] [中文文档][更新日志]快速启动二进制goInception 下载Docker 镜像docker pull hanchuanchuan/goinception源代码编译go 版本 1.14+ (go mod)git clone ...

    MySQL Clone Plugin备份同步原理与实践.pptx

    MySQL Clone Plugin是一款强大的数据库备份和同步工具,尤其适用于MySQL环境中的快速复制和集群构建。它提供了高效、便捷的节点同步方案,避免了传统备份恢复过程中的一些繁琐步骤,减少了对业务的影响。 1. **...

    tdriver git clone的文件

    tdriver git clone的文件,具体文件如下: git clone git://gitorious.org/tdriver/driver.git git clone git://gitorious.org/tdriver/sut_qt.git git clone git://gitorious.org/tdriver/agent_qt.git git clone ...

    java_clone用法

    clonedAccount.user = (User) this.user.clone(); // 假设User类也实现了Cloneable接口 return clonedAccount; } ``` #### 七、何时选择深拷贝 并非所有的引用类型都需要进行深拷贝。如果引用的对象是不可变的...

    Qt编译MySQL驱动

    在本文中,我们将深入探讨如何在Qt环境中编译MySQL驱动,以便在Qt应用程序中与MySQL数据库进行交互。首先,我们要明确的是,这个过程通常适用于Qt 5.2及其更高版本,因为这是支持编译MySQL驱动的最低要求。在这个...

    MySQL 8.0.18使用clone plugin重建MGR的实现

    mysql -urecipient_clone_user -ppassword -h 192.168.1.12 -P3311 \ CLONE INSTANCE FROM 'donor_clone_user'@'192.168.1.11':3311 IDENTIFIED BY 'password'; ``` 克隆完成后,重启MySQL服务,并启动Group ...

Global site tag (gtag.js) - Google Analytics