Giter Site home page Giter Site logo

msops's Introduction

msops

Build Status codecov.io MIT license

A Go library for MySQL Ops. Based on go-sql-driver.

Requirements

go-sql-driver should be pre-installed

go get github.com/go-sql-driver/mysql

Installation

go get github.com/ericpai/msops

Examples

package main

import (
	"fmt"

	"github.com/ericpai/msops"
)

func main() {
	dbaUsers := []string{"dba", "dba"}
	dbaPassword := []string{"password", "password"}
	replUsers := []string{"repl", "repl"}
	replPassword := []string{"password", "password"}
	dbEndpoints := []string{"127.0.0.1:3306", "127.0.0.1:3307"}
	params := map[string]string{
		"charset": "utf8",
		"timeout": "1s",
	}

	// Register DB instances
	for i := 0; i < 2; i++ {
		if err := msops.Register(dbEndpoints[i], dbaUsers[i], dbaPassword[i], replUsers[i], replPassword[i], params); err != nil {
			fmt.Printf("Register db[%d] error: %s\n", i, err.Error())
		} else {
			defer msops.Unregister(dbEndpoints[i])
		}
	}

	// Get master status of DB0
	if masterSt, err := msops.GetMasterStatus(dbEndpoints[0]); err != nil {
		fmt.Printf("Get master status of db[0] error: %s\n", err.Error())
	} else {
		fmt.Printf("Master log file: %s, log position: %d\n", masterSt.File, masterSt.Position)
	}

	// Change DB0 to be the master of DB1
	if err := msops.ChangeMasterTo(dbEndpoints[1], dbEndpoints[0], false); err != nil {
		fmt.Printf("Change master error: %s\n", err.Error())
	}

}

User Guide

See API documentations here.

Developer Guide

If you have found bugs or want to propose some new features, please submit an issue to this repo. Pull requests are welcome as well.

Licensing

Msops is released under MIT license.

msops's People

Contributors

ericpai avatar

Stargazers

daihu avatar cucy avatar qingshunluo avatar guoke avatar Meng Wenbin avatar  avatar

Watchers

James Cloos avatar

Forkers

meguoke daihu

msops's Issues

SHOW GLOBAL VARIABLES/STATUS outputs mess codes

Some sample output

.6.30-log-�versi n
gOFFwskip_show_ atabaseOFFxslav
report_host
storage_engine InnoDB
ey.pemrshow_o d_temporalsOFF$s
le$/var/lib/mysql/83e76ba18 e9
nt_classes168*D$p rfo
ache_instances1�thread_cac e_siz
rsOFF�slave sql_
ed_mutexesOFF�tmp_ta le

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.