激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python如何實現MySQL實例初始化詳解

Python如何實現MySQL實例初始化詳解

2020-12-16 00:18黃杉 Python

這篇文章主要給大家介紹了關于Python如何實現MySQL實例初始化的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。

前言

相信每位程序員對mysql應該都不陌生,MySQL是一個關系型數據庫管理系統,由瑞典MySQL AB 公司開發,目前屬于 Oracle 旗下產品。我們在日常開發中少不了要接觸mysql。

騰訊云上的mysql實例初始化的時候,需要自己點擊“初始化按鈕”,然后還要手動輸入16位復雜的密碼,這個操作比較繁瑣,而且如果你一次建立多個實例,這個操作量就很大了,所以必須想辦法提高效率,于是就有了下文,批量調用sdk api來實現。

本文主要給大家介紹了關于Python實現MySQL實例初始化的相關內容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧。

示例代碼

代碼準備:initstance.py

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
from src.QcloudApi.qcloudapi import QcloudApi
from time import ctime,sleep
from getpwd import get_password
 
def initinstance(cdbid,no):
module = 'cdb'
action = 'CdbMysqlInit'
config = {
 'Region': 'ap-shanghai',
 'secretId': 'AKIDTsEEl8ZK9mHcotf4OYk2A7uYxxxxxxxx',
 'secretKey': 'IOI0Zw87vYDvhR6a5QZXouomxxxxxxxx',
 'method': 'get'
}
 
pwd=get_password(16)
params = {
 'cdbInstanceId': cdbid,
 'charset': 'utf8mb4',
 'port': 3306,
 'lowerCaseTableNames': 1,
 'password': pwd
}
 
print params
try:
 service = QcloudApi(module, config)
 print service.generateUrl(action, params)
 print service.call(action, params)
except Exception, e:
 print 'exception:', e
 
def main():
# 這里添加 N多實例id,可以批量進行初始化,不用再界面點擊操作了。
cdbids_hermes=["cdb-1hz14ogho","cdb-1417ds7su"]
for index,value in enumerate(cdbids_hermes):
 initinstance(value,str((index+1)).zfill(2))
 sleep(1)
 
if __name__ == '__main__':
main()

初始化實例腳本initstance.py,準備執行代碼:

調試報錯,需要安裝qcloudapi-sdk-python-master.zip

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[hy@orcl ] /data0/dbj1st$ python initstance.py
Traceback (most recent call last):
File "initstance.py", line 2, in <module>
from src.QcloudApi.qcloudapi import QcloudApi
ImportError: No module named src.QcloudApi.qcloudapi
[hy@orcl ] /data0/dbj1st$
 
[hy@orcl ] /data0/dbj1st/promotion$ unzip qcloudapi-sdk-python-master.zip
Archive: qcloudapi-sdk-python-master.zip
e6cb9ff252cdb125e516525a2bb62d3410723adf
creating: qcloudapi-sdk-python-master/
extracting: qcloudapi-sdk-python-master/.gitignore
inflating: qcloudapi-sdk-python-master/README.md
inflating: qcloudapi-sdk-python-master/demo.py
creating: qcloudapi-sdk-python-master/src/
creating: qcloudapi-sdk-python-master/src/QcloudApi/
extracting: qcloudapi-sdk-python-master/src/QcloudApi/__init__.py
creating: qcloudapi-sdk-python-master/src/QcloudApi/common/
extracting: qcloudapi-sdk-python-master/src/QcloudApi/common/__init__.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/common/request.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/common/sign.py
creating: qcloudapi-sdk-python-master/src/QcloudApi/modules/
extracting: qcloudapi-sdk-python-master/src/QcloudApi/modules/__init__.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/account.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/base.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/bill.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/bm.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/cbs.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/cdb.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/cdn.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/cmem.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/cvm.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/dfw.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/eip.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/image.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/lb.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/live.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/market.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/monitor.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/redis.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/scaling.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/sec.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/snapshot.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/tdsql.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/trade.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/vod.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/vpc.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/wenzhi.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/modules/yunsou.py
inflating: qcloudapi-sdk-python-master/src/QcloudApi/qcloudapi.py
extracting: qcloudapi-sdk-python-master/src/__init__.py
[hy@orcl ] /data0/dbj1st/promotion$ ll
[hy@orcl ] /data0/dbj1st/promotion$ cp -r qcloudapi-sdk-python-master/src .
[hy@orcl ] /data0/dbj1st/promotion$

需要安裝cassdk

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[hy@orcl ] /data0/dbj1st/promotion$ python initstance.py
6
exception: No module named requests
[hy@orcl ] /data0/dbj1st/promotion$
[hy@orcl ] /data0/dbj1st/promotion$
[hy@orcl ] /data0/dbj1st/promotion$ sudo su
[root@dbj4st] /data0/dbj1st/promotion$ pip install cassdk
Collecting cassdk
Downloading cassdk-1.0.2.tar.gz
Building wheels for collected packages: cassdk
Running setup.py bdist_wheel for cassdk ... error
Complete output from command /bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-1_XMv6/cassdk/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpzGF2_Dpip-wheel- --python-tag cp27:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
 or: -c --help [cmd1 cmd2 ...]
 or: -c --help-commands
 or: -c cmd --help
 
error: invalid command 'bdist_wheel'
 
----------------------------------------
Failed building wheel for cassdk
Running setup.py clean for cassdk
Failed to build cassdk
Installing collected packages: cassdk
Running setup.py install for cassdk ... done
Successfully installed cassdk-1.0.2
[root@dbj4st] /data0/dbj1st/promotion$

需要安裝requests

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[hy@orcl ] /data0/dbj1st/promotion$ python initstance.py
6
exception: No module named requests
[hy@orcl ] /data0/dbj1st/promotion$ sudo su
[root@dbj4st] /data0/dbj1st/promotion$ sudo pip install --upgrade urllib3
Collecting urllib3
Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
100% |████████████████████████████████| 133kB 186kB/s
Installing collected packages: urllib3
Successfully installed urllib3-1.22
[root@dbj4st] /data0/dbj1st/promotion$
 
[hy@orcl ] /data0/dbj1st/promotion$ sudo su
[root@dbj4st] /data0/dbj1st/promotion$ sudo pip install --upgrade requests
Collecting requests
Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
100% |████████████████████████████████| 92kB 9.9kB/s
Collecting certifi>=2017.4.17 (from requests)
Downloading certifi-2017.7.27.1-py2.py3-none-any.whl (349kB)
100% |████████████████████████████████| 358kB 36kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 18kB/s
Collecting idna<2.7,>=2.5 (from requests)
Downloading idna-2.6-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 16kB/s
Requirement already up-to-date: urllib3<1.23,>=1.21.1 in /usr/lib/python2.7/site-packages (from requests)
Installing collected packages: certifi, chardet, idna, requests
Found existing installation: chardet 2.2.1
Uninstalling chardet-2.2.1:
 Successfully uninstalled chardet-2.2.1
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4
[root@dbj4st] /data0/dbj1st/promotion$

需要安裝DependencyWarning

?
1
2
3
4
[laobanzhang@dbj1st] ~/dbj1st/promotion$ python initstance.py
6
exception: cannot import name DependencyWarning
[laobanzhang@dbj1st] ~/dbj1st/promotion$

OK,執行成功:

?
1
2
3
4
5
[hy@orcl ] /data0/dbj1st/promotion$ python initstance.py
6
7
{"code":0,"message":"","codeDesc":"Success","jobId":51783}
[hy@orcl ] /data0/dbj1st/promotion$

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。

原文鏈接:http://blog.csdn.net/mchdba/article/details/78453115

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91香蕉国产亚洲一区二区三区 | 久久9999久久 | 久久久婷婷 | 成人福利在线视频 | 国产成人高清成人av片在线看 | 久久久日韩精品一区二区 | 成年人在线免费播放视频 | 成人福利在线免费观看 | 精品亚洲午夜久久久久91 | 成人免费电影在线观看 | 黄色欧美精品 | 91久久久久久亚洲精品禁果 | omofun 动漫在线观看 | 色综合久久久久久久久久久 | 日韩电影一区二区 | 毛片大全在线观看 | 欧美天堂一区 | a视频在线播放 | 激情在线视频 | 精品三级内地国产在线观看 | 国产精品久久久久久模特 | 亚洲午夜不卡 | 1314成人网| 偿还的影视高清在线观看 | 国产精品伦视频看免费三 | 国产做爰全免费的视频黑人 | 特级黄一级播放 | 精品国产精品久久 | 五月婷婷第四色 | 一本色道久久久888 香蕉视频99 | 特级黄色一级毛片 | 欧美日韩电影在线 | 日本aⅴ在线 | 九九热九九热 | 精品久久久久久久久久久αⅴ | 男人午夜小视频 | 毛片网站视频 | 看免费5xxaaa毛片 | 国产资源视频在线观看 | 久久久青 | 99精品国产在热久久婷婷 |