1)myini
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=C:\mysql-8.0.11-winx64
# 设置mysql数据库的数据的存放目录,data文件夹它会自行创建,不要自己手动创建
datadir= C:\mysql-8.0.11-winx64\Data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
innodb_buffer_pool_size=521M
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
2)以管理员身份运行cmd
3)C:\mysql-8.0.11-winx64\bin>mysqld --initialize --console
2024-05-08T05:29:52.004874Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 6628
2024-05-08T05:29:58.923354Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: X9SSp?ZCwarq
2024-05-08T05:30:03.681372Z 0 [System] [MY-013170] [Server] C:\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
4)C:\mysql-8.0.11-winx64\bin>mysqld --install mysql8
Service successfully installed.
5)C:\mysql-8.0.11-winx64\bin>net start mysql8
mysql8 服务正在启动 .
mysql8 服务已经启动成功。
6)登录mysql
mysql -uroot -p
7)修改root密码
alter user 'root'@'localhost' IDENTIFIED BY 'roottest001';
flush privileges;
8)重新登陆
9)ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'roottest001';(修改root密码)
10)创建数据库,带编码格式;
create database mydb1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
create database xiaozhu DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
11)创建用户
create user 'test'@'192.168.%' identified by 'test002' PASSWORD EXPIRE NEVER;
ALTER USER 'test'@'192.168.%' IDENTIFIED WITH mysql_native_password BY 'test002';
GRANT ALL ON test.* TO 'mydb1'@'192.168.%';