当前位置: 首页>>代码示例>>Python>>正文


Python Connection.get方法代码示例

本文整理汇总了Python中torndb.Connection.get方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get方法的具体用法?Python Connection.get怎么用?Python Connection.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torndb.Connection的用法示例。


在下文中一共展示了Connection.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remote_start_mysql_server

# 需要导入模块: from torndb import Connection [as 别名]
# 或者: from torndb.Connection import get [as 别名]
def remote_start_mysql_server(v_host,v_os_user,v_os_password,
    v_db_port): 

    # v_mysql_version 1: mysql5 4:mariadb5 5:mariadb10
    # 
    db = Connection('/tmp/mysql3306.sock',
                    config.DB_NAME,
                    config.DB_USER,
                    config.DB_PASSWD,
                    time_zone='+8:00')

    # 获得Mysql server 版本: mysql5,mariadb5,mariadb10
    v_get_sql = r'''SELECT case mysql_version when 1 then 'mysql5' when 4 then 'mariadb5' when 5 then 'mariadb10' when 6 then 'percona5.6' when 7 then 'pxc5.6' end mysql_version from tag where ip='%s' and port=%d ''' % (v_host,int(v_db_port))

    v_list = db.get(v_get_sql)

    v_mysql_version = v_list['mysql_version']
            

    db.close()

            
    #v_db_socket='--socket=/tmp/mysql'+str(v_db_port)+'.sock'
    #nohup 防止paramiko 进程退出后,中断执行
    # 必须要加 1>/dev/null 2>&1,否则命令不执行。可能是paramiko 模式下,不加的话,执行命令时日志无法输出
    
    v_exe_cmd = r'''nohup /apps/svr/%s/bin/mysqld_safe --defaults-file=%s/%s_%d.cnf 1>/dev/null 2>&1 &''' % (
                v_mysql_version,config.mysql_conf_path,v_mysql_version,v_db_port)

    print v_exe_cmd

    # 远程paramiko调用 在本机执行sql  

    result = remote_shell_cmd_no_result(v_host,v_os_user,v_os_password,v_exe_cmd)

    time.sleep(20)   # 等待20秒 mysql 完全启动,更好的方法是,做个循环判断mysql 完全起来了,再退出



    
    return result  #返回空串表示成功
开发者ID:gioh,项目名称:webdbtool,代码行数:43,代码来源:remote_db_execute.py

示例2: remote_off_get_datadir_path

# 需要导入模块: from torndb import Connection [as 别名]
# 或者: from torndb.Connection import get [as 别名]
def remote_off_get_datadir_path(v_host,v_db_port,v_type): 

        
    # v_mysql_version 1: mysql5 4:mariadb5 5:mariadb10
    # 
    db = Connection('/tmp/mysql3306.sock',
                    config.DB_NAME,
                    config.DB_USER,
                    config.DB_PASSWD,
                    time_zone='+8:00')

    # 获得Mysql server 版本: mysql5,mariadb5,mariadb10
    v_get_sql = r'''SELECT case mysql_version when 1 then 'mysql5' when 4 then 'mariadb5' when 5 then 'mariadb10' when 6 then 'percona5.6' when 7 then 'pxc5.6' end mysql_version from tag where ip='%s' and port=%d ''' % (v_host,int(v_db_port))

    v_list = db.get(v_get_sql)

    v_mysql_version = v_list['mysql_version']
            

    db.close()

    # /apps/dbdat/mariadb10_data3306
    # 
    if v_type==1:

        v_datadir_path = '%s/%s_data%s' % (config.mysql_datadir_path,v_mysql_version,v_db_port)

    else:

        v_datadir_path = '%s_data%s' % (v_mysql_version,v_db_port)
    
   
    print v_datadir_path

    
    
    return v_datadir_path
开发者ID:gioh,项目名称:webdbtool,代码行数:39,代码来源:remote_db_execute.py

示例3: add_single_backup_job

# 需要导入模块: from torndb import Connection [as 别名]
# 或者: from torndb.Connection import get [as 别名]
def add_single_backup_job(v_setup_id):  # mysql_ins_bak_setup 表的当前更新或插入的备份实例id

    os_user = config.OS_USER

    os_password = config.OS_APPS_PASSWD

    scheduler = BackgroundScheduler()  # 默认内存的jobstore

    url = "sqlite:////home/apps/dbajob.sqlite"

    scheduler.add_jobstore("sqlalchemy", url=url, alias="sqlite_js")

    scheduler.print_jobs()

    print "a"

    # 连接配置中心库,获取数据库备份周期等信息
    db = Connection("/tmp/mysql3306.sock", config.DB_NAME, config.DB_USER, config.DB_PASSWD, time_zone="+8:00")

    v_sql = r"""SELECT a.instance_id,b.ip,b.port,a.backup_interval_type,a.backup_start_time from mysql_ins_bak_setup a,tag b where 
        a.instance_id=b.id and a.id=%d""" % (
        v_setup_id
    )

    print v_sql

    bak_server = db.get(v_sql)

    instance_id = bak_server["instance_id"]

    from_host = bak_server["ip"]

    # print from_host

    mysql_port = bak_server["port"]

    backup_interval_type = bak_server["backup_interval_type"]

    backup_start_time = bak_server["backup_start_time"]

    str_start_date = time.strftime("%Y-%m-%d") + " " + backup_start_time

    print str_start_date

    v_job_id = "backup_%s_%s" % (from_host, str(mysql_port))

    if backup_interval_type == 1:  # every day

        # scheduler.add_interval_job(backup, days=1, start_date=str_start_date, args=[from_host, mysql_port, os_user, os_password], jobstore='file')

        scheduler.add_job(
            backup,
            "interval",
            id=v_job_id,
            days=1,
            start_date=str_start_date,
            args=[from_host, mysql_port, os_user, os_password],
            replace_existing=True,
            jobstore="sqlite_js",
        )

    elif backup_interval_type == 2:  # every week weeks=1

        scheduler.add_job(
            backup,
            "interval",
            id=v_job_id,
            weeks=1,
            start_date=str_start_date,
            args=[from_host, mysql_port, os_user, os_password],
            replace_existing=True,
            jobstore="sqlite_js",
        )

    elif backup_interval_type == 3:  # every hour hours=1

        scheduler.add_job(
            backup,
            "interval",
            id=v_job_id,
            hours=1,
            start_date=str_start_date,
            args=[from_host, mysql_port, os_user, os_password],
            replace_existing=True,
            jobstore="sqlite_js",
        )

    else:
        pass

    scheduler.print_jobs()

    print "b"

    scheduler.start()

    scheduler.print_jobs()

    print "c"

#.........这里部分代码省略.........
开发者ID:gioh,项目名称:webdbtool,代码行数:103,代码来源:mysql_sche_backup_call.py


注:本文中的torndb.Connection.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。