1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      python怎么讓數(shù)據(jù)庫的表遷移到另一臺(tái)服務(wù)器

      本篇內(nèi)容主要講解“python怎么讓數(shù)據(jù)庫的表遷移到另一臺(tái)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“python怎么讓數(shù)據(jù)庫的表遷移到另一臺(tái)服務(wù)器”吧!

      本篇內(nèi)容主要講解“python怎么讓數(shù)據(jù)庫的表遷移到另一臺(tái)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“python怎么讓數(shù)據(jù)庫的表遷移到另一臺(tái)服務(wù)器”吧!

      創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站制作、成都網(wǎng)站建設(shè)、恩施土家網(wǎng)絡(luò)推廣、微信小程序開發(fā)、恩施土家網(wǎng)絡(luò)營銷、恩施土家企業(yè)策劃、恩施土家品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供恩施土家建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com

      安裝-python

      要想使python可以操作mysql 就需要MySQL-python驅(qū)動(dòng),它是python 操作mysql必不可少的模塊。

      下載地址:https://pypi.python.org/pypi/MySQL-python/

      下載MySQL-python-1.2.5.zip 文件之后直接解壓。進(jìn)入MySQL-python-1.2.5目錄:

      >>python setup.py install

      報(bào)錯(cuò):

      [root@S220 MySQL-python-1.2.5]# python setup.py install

      sh: mysql_config: command not found

      Traceback (most recent call last):

      File "setup.py", line 17, in

      metadata, options = get_config()

      File "/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config

      libs = mysql_config("libs_r")

      File "/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config

      raise EnvironmentError("%s not found" % (mysql_config.path,))

      EnvironmentError: mysql_config not found

      解決辦法:手工安裝mysql_python

      在setup_posix.py內(nèi)找到mysql_config.path=/xxx/xxx(mysql安裝路徑/bin/mysql_config)

      如下:

      [root@S220 MySQL-python-1.2.5]# vi  setup_posix.py

      import os, sys

      from ConfigParser import SafeConfigParser

      # This dequote() business is required for some older versions

      # of mysql_config

      def dequote(s):

      if s[0] in "\"'" and s[0] == s[-1]:

      s = s[1:-1]

      return s

      def compiler_flag(f):

      return "-%s" % f

      def mysql_config(what):

      from os import popen

      f = popen("%s --%s" % (mysql_config.path, what))

      data = f.read().strip().split()

      ret = f.close()

      if ret:

      if ret/256:

      data = []

      if ret/256 > 1:

      raise EnvironmentError("%s not found" % (mysql_config.path,))

      return data

      mysql_config.path ='/home/mysql/bin/mysql_config'

      def get_config():

      from setup_common import get_metadata_and_options, enabled, create_release_file

      之后:

      [root@S220 MySQL-python-1.2.5]# python setup.py install

      running install

      在包含自 _mysql.c:44 的文件中:

      /home/mysql/include/my_config.h:442:1: 警告:“HAVE_WCSCOLL”重定義

      在包含自 /usr/local/include/python2.7/Python.h:8 的文件中,

      從 _mysql.c:29:

      /usr/local/include/python2.7/pyconfig.h:902:1: 警告:這是先前定義的位置

      copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants

      Processing dependencies for MySQL-python==1.2.5

      Finished processing dependencies for MySQL-python==1.2.5

      至此MySQL-python驅(qū)動(dòng)安裝成功。。。。。。

      把mysql查出的內(nèi)容放到一個(gè)列表中:

      [root@S220 ~]# cat mysqldump.py

      #!/usr/bin/python

      #-*_ coding:UTF-8 _*_

      import MySQLdb

      conn= MySQLdb.connect(

      host='192.168.0.144',

      port = 3306,

      user='root',

      passwd='admin',

      db ='jf',

      )

      cur = conn.cursor()

      dbs=cur.execute('show databases')

      mail_list=[]

      #獲取所有結(jié)果

      databases = cur.fetchall()

      result=list(databases)

      for r in result:

      mail_list.append(r)

      print mail_list

      [root@S220 ~]# python mysqldump.py

      [('ad',), ('agency',), ('beifen',), ('chinabidding',), ('crm',), ('crm2',), ('data',), ('dingyue',), ('experience',), ('fxb2016',), ('hdzq',), ('history',), ('info',), ('info_addition',), ('info_back',), ('information_schema',), ('infoservice',), ('jf',), ('jf2016',), ('liuwenhe',), ('log',), ('mailer',), ('mysql',), ('performance_schema',), ('resin_session',), ('sbiao',), ('sbw2',), ('stat',), ('test',), ('web',), ('weblog',), ('winfo',)]

      上面的結(jié)果中是一個(gè)列表中又有一個(gè)元祖,這不是我們想要的結(jié)果,所以先循環(huán)列表再循環(huán)元祖,這樣可以真正做到把數(shù)據(jù)庫查出的內(nèi)容存到一個(gè)列表中。如下紅色部分。

      [root@S220 ~]# cat mysqldump.py

      #!/usr/bin/python

      #-*_ coding:UTF-8 _*_

      import MySQLdb

      conn= MySQLdb.connect(

      host='192.168.0.144',

      port = 3306,

      user='root',

      passwd='admin',

      db ='jf',

      )

      cur = conn.cursor()

      dbs=cur.execute('show databases')

      mail_list=[]

      #獲取所有結(jié)果

      databases = cur.fetchall()

      result=list(databases)

      for r in result:

      mail_list.append(r)

      dbs_list=[]

      for db in mail_list:

      for db1 in db:

      dbs_list.append(db1)

      print(dbs_list)

      下面是寫的一個(gè)python腳本,用來完成從一臺(tái)mysql服務(wù)器遷移到另一臺(tái)mysql服務(wù)器,一個(gè)表一個(gè)表的遷移,這試用于搭建主從,或者搭建測(cè)試環(huán)境的場(chǎng)景。我這個(gè)未來便于理解,寫的有點(diǎn)多余,其實(shí)不需要把取出來的庫和下面的表名字,放到一個(gè)列表中這2步驟。

      [root@S220 ~]# cat  mysqldump.py

      #!/usr/bin/python

      #-*_ coding:UTF-8 _*_

      import MySQLdb

      import os

      conn= MySQLdb.connect(

      host='192.168.0.144',

      port = 3306,

      user='root',

      passwd='***',

      db ='jf',

      )

      cur = conn.cursor()

      dbs=cur.execute('show databases')

      mail_list=[]

      #獲取所有結(jié)果

      databases = cur.fetchall()

      result=list(databases)

      for r in result:

      mail_list.append(r)

      dbs_list=[]

      for db in mail_list:

      for db1 in db:

      dbs_list.append(db1)

      conn.close()

      cur.close()

      tables_list=[]

      for db2 in dbs_list:

      if db2=='liuwenhe':

      conn_name={"host":"192.168.0.**","user":"root","passwd":"ad****min","db":db2}

      conn1= MySQLdb.connect(**conn_name)

      cur_new = conn1.cursor()

      tbs=cur_new.execute('show tables')

      tbs_list=[]

      tables = cur_new.fetchall()

      result=list(tables)

      for t in result:

      tbs_list.append(t)

      for tb1 in tbs_list:

      for tb2 in tb1:

      tables_list.append(tb2)

      conn1.close()

      cur_new.close()

      for table in tables_list:

      dumpcmd = "/home/mysql/bin/mysqldump -uroot " + " --opt  " " -padmin  " +" -h292.168.0.** " +"-d " +db2 +" "+table +" > " + "/backup/" + db2 +"_"+table+ ".sql"

      os.system(dumpcmd)

      sql1="/home/mysql/bin/mysql "+"-uroot "+"-pg****in@123 "+"-h292.168.0.220 "+db2 +"

      os.system(sql1)

      print "data translate completed"


      新聞標(biāo)題:python怎么讓數(shù)據(jù)庫的表遷移到另一臺(tái)服務(wù)器
      本文地址:http://www.ef60e0e.cn/article/cophj.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        浦东新区| 伊金霍洛旗| 高尔夫| 彭泽县| 泌阳县| 德惠市| 丰镇市| 邵武市| 喀喇| 临江市| 册亨县| 监利县| 金昌市| 石屏县| 兴文县| 岳池县| 安义县| 藁城市| 公主岭市| 永清县| 永平县| 耿马| 宣武区| 和平区| 张掖市| 上饶市| 北宁市| 湄潭县| 蓬溪县| 烟台市| 应用必备| 乌海市| 赣榆县| 银川市| 庄河市| 永济市| 西乌珠穆沁旗| 体育| 公主岭市| 青浦区| 卢龙县|