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
版权声明:本文为sforiz原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。