mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
mysql57 init
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
[client]
|
||||
user = root
|
||||
#password = your_password
|
||||
port = 3306
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
default-character-set = UTF8MB4
|
||||
|
||||
[mysqld]
|
||||
port = 3306
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
default_storage_engine = MyISAM
|
||||
|
||||
key_buffer_size = 8M
|
||||
table_open_cache = 32
|
||||
sort_buffer_size = 256K
|
||||
net_buffer_length = 4K
|
||||
read_buffer_size = 128K
|
||||
read_rnd_buffer_size = 256K
|
||||
myisam_sort_buffer_size = 4M
|
||||
thread_cache_size = 4
|
||||
lower_case_table_names=0
|
||||
tmp_table_size = 8M
|
||||
character-set-server = UTF8MB4
|
||||
|
||||
max_connections = 500
|
||||
max_connect_errors = 100
|
||||
open_files_limit = 2560
|
||||
max_allowed_packet = 128M
|
||||
|
||||
#skip-external-locking
|
||||
#skip-grant-tables
|
||||
#loose-skip-innodb
|
||||
#skip-networking
|
||||
#skip-name-resolve
|
||||
|
||||
log-bin=mysql-bin
|
||||
binlog_format=mixed
|
||||
server-id = 1
|
||||
slow_query_log=1
|
||||
slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log
|
||||
long_query_time=3
|
||||
#log_queries_not_using_indexes=on
|
||||
|
||||
relay-log=mdserver
|
||||
relay-log-index=mdserver
|
||||
|
||||
#master
|
||||
#binlog-do-db
|
||||
binlog-ignore-db = test
|
||||
binlog-ignore-db = mysql
|
||||
binlog-ignore-db = information_schema
|
||||
binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log-slave-updates
|
||||
#replicate-do-db
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_buffer_pool_size = 16M
|
||||
innodb_log_file_size = 5M
|
||||
innodb_log_buffer_size = 8M
|
||||
innodb_flush_log_at_trx_commit = 1
|
||||
innodb_lock_wait_timeout = 120
|
||||
innodb_max_dirty_pages_pct = 90
|
||||
innodb_read_io_threads = 1
|
||||
innodb_write_io_threads = 1
|
||||
innodb_file_per_table=1
|
||||
binlog_expire_logs_seconds=2592000
|
||||
|
||||
[mysqldump]
|
||||
quick
|
||||
|
||||
[mysql]
|
||||
no-auto-rehash
|
||||
|
||||
[myisamchk]
|
||||
key_buffer_size = 20M
|
||||
sort_buffer_size = 20M
|
||||
read_buffer = 2M
|
||||
write_buffer = 2M
|
||||
|
||||
[mysqlhotcopy]
|
||||
interactive-timeout
|
||||
+79
-5
@@ -284,6 +284,19 @@ def initMysqlData():
|
||||
return 1
|
||||
|
||||
|
||||
def initMysql57Data():
|
||||
datadir = getDataDir()
|
||||
if not os.path.exists(datadir + '/mysql'):
|
||||
serverdir = getServerDir()
|
||||
myconf = serverdir + "/my.cnf"
|
||||
user = pGetDbUser()
|
||||
cmd = 'cd ' + serverdir + ' && ./bin/mysqld --defaults-file=' + myconf + \
|
||||
' --initialize --explicit_defaults_for_timestamp'
|
||||
mw.execShell(cmd)
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
||||
def initMysql8Data():
|
||||
datadir = getDataDir()
|
||||
if not os.path.exists(datadir + '/mysql'):
|
||||
@@ -328,13 +341,13 @@ def initMysql8Pwd():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep mysql|grep -v grep|grep -v py|grep -v init.d|awk '{print $2}'")
|
||||
if data[0] != "":
|
||||
#print("mysql start ok!")
|
||||
# print("mysql start ok!")
|
||||
is_start = True
|
||||
break
|
||||
time.sleep(0.5)
|
||||
|
||||
if not is_start:
|
||||
#print("mysql start fail!")
|
||||
# print("mysql start fail!")
|
||||
return False
|
||||
|
||||
serverdir = getServerDir()
|
||||
@@ -348,7 +361,8 @@ def initMysql8Pwd():
|
||||
if len(password) == 0:
|
||||
return True
|
||||
|
||||
#print('localhost', 3306, 'root', password, "/www/server/mysql/mysql.sock")
|
||||
# print('localhost', 3306, 'root', password,
|
||||
# "/www/server/mysql/mysql.sock")
|
||||
|
||||
# import MySQLdb as mdb
|
||||
# dbconn = mdb.connect(host='localhost', port=3306, user='root',
|
||||
@@ -399,6 +413,64 @@ def myOp(version, method):
|
||||
return str(e)
|
||||
|
||||
|
||||
def my57cmd(version, method):
|
||||
init_file = initDreplace()
|
||||
cmd = init_file + ' ' + method
|
||||
gsDir = getServerDir()
|
||||
sql_file_path = "/tmp/tmp_sql57.sql"
|
||||
|
||||
try:
|
||||
initData = initMysql57Data()
|
||||
|
||||
cmd_start1 = gsDir + '/bin/mysqld_safe --defaults-file=' + \
|
||||
gsDir + '/my.cnf --skip-grant-tables &'
|
||||
subprocess.Popen(cmd_start1, stdout=subprocess.PIPE, shell=True,
|
||||
bufsize=4096, stderr=subprocess.PIPE)
|
||||
time.sleep(2)
|
||||
|
||||
sql = "use mysql;\
|
||||
flush privileges;\
|
||||
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;\
|
||||
update user set authentication_string = password('root123') where user = 'root';\
|
||||
flush privileges ;"
|
||||
mw.writeFile(sql_file_path, sql)
|
||||
|
||||
cmd_init_one = gsDir + "/bin/mysql --defaults-file=" + \
|
||||
gsDir + "/my.cnf -uroot -p' ' < " + sql_file_path
|
||||
|
||||
subprocess.Popen(cmd_init_one, stdout=subprocess.PIPE, shell=True,
|
||||
bufsize=4096, stderr=subprocess.PIPE)
|
||||
|
||||
cmd_kill = "ps -ef|grep mysql |grep -v grep|awk '{print $2}'|xargs kill"
|
||||
mw.execShell(cmd_kill)
|
||||
|
||||
cmd_start2 = gsDir + '/bin/mysqld_safe --defaults-file=' + gsDir + '/my.cnf &'
|
||||
subprocess.Popen(cmd_start2, stdout=subprocess.PIPE, shell=True,
|
||||
bufsize=4096, stderr=subprocess.PIPE)
|
||||
|
||||
sql = "SET PASSWORD = PASSWORD('root'); use mysql; flush privileges;\
|
||||
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER ;\
|
||||
update user set authentication_string = password('root') where user = 'root' ;\
|
||||
flush privileges;"
|
||||
mw.writeFile(sql_file_path, sql)
|
||||
|
||||
cmd_init_two = gsDir + "/bin/mysql --defaults-file=" + gsDir + \
|
||||
"/my.cnf --connect-expired-password -uroot -proot123 < " + sql_file_path
|
||||
subprocess.Popen(cmd_init_two, stdout=subprocess.PIPE, shell=True,
|
||||
bufsize=4096, stderr=subprocess.PIPE)
|
||||
|
||||
cmd_init_stop = gsDir + \
|
||||
"/bin/mysqladmin --defaults-file=" + gsDir + "/my.cnf -uroot -proot shutdown"
|
||||
|
||||
subprocess.Popen(cmd_init_stop, stdout=subprocess.PIPE, shell=True,
|
||||
bufsize=4096, stderr=subprocess.PIPE)
|
||||
# if initData == 0:
|
||||
# initMysqlPwd()
|
||||
return 'ok'
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
|
||||
def my8cmd(version, method):
|
||||
# mysql 8.0 ok
|
||||
init_file = initDreplace(version)
|
||||
@@ -439,8 +511,10 @@ def my8cmd(version, method):
|
||||
|
||||
|
||||
def appCMD(version, action):
|
||||
if version == '8.0' or version == '5.7':
|
||||
if version == '8.0':
|
||||
return my8cmd(version, action)
|
||||
if version == '5.7':
|
||||
return my57cmd(version, action)
|
||||
return myOp(version, action)
|
||||
|
||||
|
||||
@@ -1485,7 +1559,7 @@ def getMasterStatus(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
#print(dlist, len(dlist))
|
||||
# print(dlist, len(dlist))
|
||||
if len(dlist) > 0 and (dlist[0][10] == 'Yes' or dlist[0][11] == 'Yes'):
|
||||
data['slave_status'] = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user