1.下载mysql8的安装包
目录
下载地址:MySQL :: Download MySQL Community Server
解压后图所示
2.在解压后的目录创建 my.ini 文件
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\mysql8
# 设置mysql数据库的数据的存放目录
datadir=D:\mysql8\data
# 允许最大连接数
max_connections=200
#允许连接失败的次数。防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
authentication_policy=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
3.初始化mysql并启动mysql
D:\mysql8\bin>mysqld --initialize --console
2023-01-04T08:56:03.696481Z 0 [System] [MY-013169] [Server] D:\mysql8\bin\mysqld.exe (mysqld 8.0.31) initializing of server in progress as process 10848
2023-01-04T08:56:03.732872Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-04T08:56:04.563335Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-04T08:56:06.156571Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Fl%NNjL)L83/
D:\mysql8\bin>mysqld --console --skip-grant-tables --shared-memory
2023-01-04T08:57:25.523164Z 0 [System] [MY-010116] [Server] D:\mysql8\bin\mysqld.exe (mysqld 8.0.31) starting as process 10580
2023-01-04T08:57:25.543078Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-04T08:57:26.148671Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-04T08:57:26.445749Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx reported: 'All I/O interfaces are disabled, X Protocol won't be accessible'
2023-01-04T08:57:26.663361Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-01-04T08:57:26.663661Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-01-04T08:57:26.760116Z 0 [System] [MY-010931] [Server] D:\mysql8\bin\mysqld.exe: ready for connections. Version: '8.0.31' socket: '' port: 0 MySQL Community Server - GPL.
4.修改mysql为远程登录和登录密码
use mysql;
update user set host='%' where user='root';
flush privileges;
alter user 'root'@'%' identified by 'Nhxa_123456@#ft';
flush privileges;
use mysql;
alter user 'root'@'%' identified with mysql_native_password by 'Nhxa_123456@#ft';
flush privileges;
D:\mysql8\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> alter user 'root'@'%' identified by 'Nhxa_123456@#ft';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Database changed
mysql> alter user 'root'@'%' identified with mysql_native_password by 'Nhxa_123456@#ft';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
6.mysql安装为windows服务并启动
D:\mysql8\bin>mysqld -install mysql8
Service successfully installed.
D:\mysql8\bin>net start mysql8
mysql8 服务正在启动 .
mysql8 服务已经启动成功。
D:\mysql8\bin>
7停止mysql服务并移除windows服务
D:\mysql8\bin>net stop mysql8
mysql8 服务正在停止..
mysql8 服务已成功停止。
D:\mysql8\bin>mysqld -remove mysql8
Service successfully removed.