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 @   chenjianwen  阅读(293)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示