mysql - 更新多个数据库的 Shell 脚本

标签 mysql shell

这是我目前拥有的:

#!/bin/bash
# Shell script to backup MySql database

MyUSER="root"
MyPASS="password123"

MYSQL="$mysql"
MYSQLDUMP="$mysqldump"

# Store list of databases
DBS=""

# Get all database list first
DBS="$($MYSQL -u $MyUSER -h -p$MyPASS -Bse 'show databases')"

for db in $DBS
do

我遇到的问题是“do”位,

我需要将其写入 shell 中。

获取所有数据库名称后,执行以下操作:

更新了用户设置密码=“passowrd”,其中 id = 999;

有人可以帮忙吗?

最佳答案

尝试

for db in $DBS
do
    $MYSQL -u $MyUSER -h -p$MyPASS -Bse "update $db.password='password' whereid =999;'
end

因为您可以在mysql中通过databasename.tablename轻松访问表。

关于mysql - 更新多个数据库的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1888725/

相关文章:

mysql - 如何调试: Subquery returns more than 1 row

PHP MySQL 性能建议

cron - 找不到从 cronjob 命令运行的 bash 脚本

Windows 批处理 : analogue for `timeout` command

c - fgets 从提示符中读取换行符

mysql - 分隔符$$和//有什么区别

php - 在 mysql 表名中使用 php uniqid 会导致偶尔出现错误 - 如何避免它?

PHP/MySQL - 删除不工作

ios - oclint-json-编译-数据库错误

shell - UNIX - 格式化另一个 shell 脚本 - 在 sed 中使用 awk