Skip to content

分库分表场景脚本批量修改表结构 #1

@daikaixian

Description

@daikaixian
#!/usr/bin/expect

set USER "test"
set HOST "10.10.10.10"

foreach j {0 1 2 3 4 5 6 7 } {
    set DATABASE ""
    append DATABASE "db00" $j
    
    spawn mysql -h $HOST  -u $USER $DATABASE -p
    expect "*password*"

    send "PASSWORD\n"

    expect "*mysql*"

    for {set i 0} {$i < 16} {incr i 1} {
        set TABLE ""
        set no 0
        set no [expr $j * 16 + $i]
        if { $no < 100 } {
            append TABLE "table00" $no
        } else {
            append TABLE "table0" $no
        }
        send "alter table $TABLE add column `ratio` varchar(8) NOT NULL DEFAULT '1-1' COMMENT '当前红包使用比例,默认1:1';\r\n"
        expect "*mysql*"
    }
    expect "*mysql*"
    send "exit;\n"
}


interact

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions