MySQL8初始化账户创建及权限分配
Posted sforiz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL8初始化账户创建及权限分配相关的知识,希望对你有一定的参考价值。
1、MySQL8没有初始的data目录,需要在使用前进行初始化。
mysql8下载地址:MySQL :: Download MySQL Community Server
基本配置文件 my.cnf
[mysqld]
basedir = D:\\mysql
datadir = D:\\mysql\\data
port = 3336
character-set-server = utf8mb4
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
数据库初始化:mysqld --initialize
数据库初始化后随机密码在日志文件中hostname.err,需要使用该密码登录并修改密码。
alter user 'root'@'localhost' identified by "password";
alter user 'root'@'localhost' identified with mysql_native_password by "root";
alter user 'root'@'localhost' identified with caching_sha2_password by "root";
MySQL8默认的认证插件是caching_sha2_password,很多客户端都不支持,可将默认的认证插件修改为mysql_native_password,在配置文件中配置default_authentication_plugin=mysql_native_password
。
2、创建账号及权限分配
#创建账号、分配权限
CREATE USER 'sky'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'sky'@'localhost' WITH GRANT OPTION;
CREATE USER 'sky'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'sky'@'%' WITH GRANT OPTION;
CREATE USER 'sky'@'localhost' IDENTIFIED BY 'password';
GRANT RELOAD,PROCESS ON *.* TO 'sky'@'localhost';
#显示账号及权限相关信息
SHOW GRANTS FOR 'sky'@'localhost';
SHOW CREATE USER 'sky'@'localhost';
MySQL账号管理相关参考:
https://dev.mysql.com/doc/refman/8.0/en/adding-users.html
https://dev.mysql.com/doc/refman/8.0/en/account-management-sql.html
以上是关于MySQL8初始化账户创建及权限分配的主要内容,如果未能解决你的问题,请参考以下文章