def install_server(db):
db.socket = str(db.installation_dir.join('mysql.sock'))
db.installation_dir.ensure_dir('tmp')
mycnf = db.installation_dir.join('my.cnf')
mycnf.write('[mysqld]\n'
'datadir=%(installation_dir)s\n'
#'log\n'
#'log-error\n'
'skip-networking\n'
'socket=mysql.sock\n'
'pid-file=mysqld.pid\n'
'tmpdir=tmp\n' % { 'installation_dir': db.installation_dir })
subprocess.check_call(['mysql_install_db', '--defaults-file=' + str(mycnf)])
server = subprocess.Popen(['mysqld', '--defaults-file=' + str(mycnf)])
import time, MySQLdb
tries = 30
for t in range(tries):
try:
with db.root() as cur:
cur.execute("CREATE USER 'abe'@'localhost' IDENTIFIED BY 'Bitcoin'")
return server
except MySQLdb.OperationalError as e:
if t+1 == tries:
raise e
time.sleep(1)
评论列表
文章目录