mysql
多实例
1.my.cnf
通过定义mysqldconfig类 mysqld_vars = {} 从里面获得很多配置文件相关参数写入字典
mysql.py
2.init DB
初始化数据库
3.修改权限
4.rc脚本启动
mysql模块 ConfigParser修改配置文件
/usr/share/mysql/各种配置文件路径
allow_no_value=True
c = ConfigParser.ConfigParser(allow_no_value=True)
In [7]: c.read('/usr/share/mysql/my-large.cnf')
Out[7]: ['/usr/share/mysql/my-large.cnf']
c.options('mysqld')
Out[10]:
['myisam_sort_buffer_size',
'skip-locking',
'read_rnd_buffer_size',
'read_buffer_size',
'log-bin',
'thread_cache_size',
'port',
'query_cache_size',
'binlog_format',
'socket',
'sort_buffer_size',
'server-id',
'max_allowed_packet',
'thread_concurrency',
'table_open_cache',
'key_buffer_size']
In [11]: c.set('mysqld','datadir','/tmp/mysql101')
In [12]: c.get('mysqld','datadir')
Out[12]: '/tmp/mysql101'
In [13]: c.write(open('/tmp/my01.cnf','w‘)
super 实现对一个父类实现调用
把一个参数传给一个属性
def __init__(self,config,**kw):
不确定接收几个参数 **kw
In [14]: def f(x,y):
....: print x
....: print y
....:
In [15]: f(1,2)
1
2
In [16]: t = (1,2)
In [18]: f(*t)
1
2
In [19]: def f(user='test',passwd='123'):
print user
print passwd
....:
In [20]: f('a','123')
a
123
In [21]: d = {'user':'test1','passwd':'123'}
In [22]: d
Out[22]: {'passwd': '123', 'user': 'test1'}
In [23]: f(**d)
test1
123
In [26]: def f(x,*args):
print x
print args
....:
In [27]: f(1,2,3)
1
(2, 3)
* 元组
**字典
In [30]: def f(x, *args, **kwargs):
print x
print args
print kwargs
....:
In [31]: f(1,2,user='test')
1
(2,)
{'user': 'test'}
setattr 设置类属性
getattr 取得类属性
setattr(a,'var3','three')
getattr(a,'var3')
mysql_install_db --defaults-file=/tmp/my01.cnf
chown -R mysql:mysql /tmp/mysql101
mysqld_safe --defaults-file=/tmp/my01.cnf &
mysql -S /var/lib/mysql/mysql.sock
-c create 创建实例
abspath取绝对路径
mysqladmin -S socket shutdown
3.mysqlDB show variables;
show global variables like '%max%';
cur.fetchall()
cur.fetchone()
转载于:https://blog.51cto.com/muzinan110/1437599