2022-10-21 18:50:38 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2022-10-27 23:09:39 +08:00
|
|
|
"compress/gzip"
|
2022-10-21 18:50:38 +08:00
|
|
|
"fmt"
|
2022-10-27 23:09:39 +08:00
|
|
|
"os"
|
2022-10-25 18:34:33 +08:00
|
|
|
"os/exec"
|
2022-10-21 18:50:38 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMysql(t *testing.T) {
|
2022-10-27 23:09:39 +08:00
|
|
|
|
|
|
|
gzipFile, err := os.Open("/tmp/ko.sql.gz")
|
2022-10-21 18:50:38 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2022-10-27 23:09:39 +08:00
|
|
|
defer gzipFile.Close()
|
|
|
|
gzipReader, err := gzip.NewReader(gzipFile)
|
2022-10-25 11:41:19 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2022-10-27 23:09:39 +08:00
|
|
|
defer gzipReader.Close()
|
2022-10-25 11:41:19 +08:00
|
|
|
|
2022-10-27 23:09:39 +08:00
|
|
|
cmd := exec.Command("docker", "exec", "-i", "365", "mysql", "-uroot", "-pCalong@2012", "kubeoperator")
|
|
|
|
cmd.Stdin = gzipReader
|
|
|
|
stdout, err := cmd.CombinedOutput()
|
|
|
|
fmt.Println(string(stdout), err)
|
2022-10-25 11:41:19 +08:00
|
|
|
}
|