mysql8.0初始化授权

初始化:

sys.stdout.write('Initializing MySQL database...\n')
self.cmd = '/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=%s --basedir=%s --user=%s' %(self.datadir, self.basedir, self.mysqluser)

启动:

self.cmd = '/usr/local/mysql/bin/mysqld_safe --defaults-file=%s --log-error=%s --slow_query_log_file=%s --socket=%s --port=%d --datadir=%s --pid-file=%s & ' %(self.mysqlconfigfile, self.logfile, self.slow_query, self.
mysql_socket, self.mysql_port, self.datadir, self.pidfile)

授权:

import mysql.connector

conn = mysql.connector.connect(host=self.mysqlhost, port=self.mysqlport, user=self.mysqluser, unix_socket=self.sock_file)
cur = conn.cursor()
ALTER_sql = "ALTER USER 'root'@'localhost' identified by '%s';"%self.root_pwd
#print ALTER_sql
cur.execute(ALTER_sql)
grant_sql = "update mysql.user set host='%s' where user='root';" %'%'
#print grant_sql
cur.execute(grant_sql)

 

posted @ 2022-05-05 16:40  chenjianwen  阅读(283)  评论(0编辑  收藏  举报