Skip to content

Commit

Permalink
fix access denied for root when executing initsql.
Browse files Browse the repository at this point in the history
  • Loading branch information
shonge authored Aug 26, 2019
1 parent 647ade9 commit 383ec54
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, MySQLdb
host = '{{ template "cluster.name" . }}-tidb'
permit_host = {{ .Values.tidb.permitHost | default "%%" | quote }}
permit_host = {{ .Values.tidb.permitHost | default "%" | quote }}
port = 4000
password_dir = '/etc/tidb/password'
conn = MySQLdb.connect(host=host, port=port, user='root', connect_timeout=5)
Expand All @@ -10,19 +10,19 @@ for file in os.listdir(password_dir):
user = file
with open(os.path.join(password_dir, file), 'r') as f:
password = f.read()
if permit_host != '%%':
conn.cursor().execute("update mysql.user set Host=%s where User='root';", (permit_host,))
conn.cursor().execute("flush privileges;")
conn.commit()
if user == 'root':
conn.cursor().execute("set password for 'root'@%s = %s;", (permit_host, password,))
conn.cursor().execute("set password for 'root'@'%%' = %s;", (password,))
else:
conn.cursor().execute("create user %s@%s identified by %s;", (user, permit_host, password,))
conn.cursor().execute("flush privileges;")
conn.commit()
{{- if .Values.tidb.initSql }}
with open('/data/init.sql', 'r') as sql:
for line in sql.readlines():
conn.cursor().execute(line)
conn.commit()
{{- end }}
if permit_host != '%%':
conn.cursor().execute("update mysql.user set Host=%s where User='root';", (permit_host,))
conn.cursor().execute("flush privileges;")
conn.commit()
conn.cursor().execute("flush privileges;")
conn.commit()

0 comments on commit 383ec54

Please sign in to comment.