下载
https://downloads.mysql.com/archives/community/
解压
建立 my.ini 文件
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\devServer\MySQL
# 设置mysql数据库的数据的存放目录
datadir=D:\devServer\MySQL\Data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
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
注意:配置中的basedir,datadir目录需要事先建立。
管理员身份,运行 cmd,进行安装
D:\devServer\mysql-8.0.22-winx64\bin>mysqld --initialize --console
2021-01-19T06:14:39.997917Z 0 [System] [MY-013169] [Server] D:\devServer\mysql-8.0.22-winx64\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 16240
2021-01-19T06:14:39.997969Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'D:\devServer\MySQL\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2021-01-19T06:14:39.998955Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-01-19T06:14:39.998962Z 0 [ERROR] [MY-013236] [Server] The designated data directory D:\devServer\MySQL\Data\ is unusable. You can remove all files that the server added to it.
2021-01-19T06:14:40.007052Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-01-19T06:14:40.007771Z 0 [System] [MY-010910] [Server] D:\devServer\mysql-8.0.22-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22) MySQL Community Server - GPL.
D:\devServer\mysql-8.0.22-winx64\bin>mysqld --initialize --console
2021-01-19T06:15:15.125680Z 0 [System] [MY-013169] [Server] D:\devServer\mysql-8.0.22-winx64\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 15060
2021-01-19T06:15:15.125733Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'D:\devServer\MySQL\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2021-01-19T06:15:15.135848Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-19T06:15:19.565832Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-19T06:15:29.002189Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: P-)Jz2vih:3;
D:\devServer\mysql-8.0.22-winx64\bin>mysqld --install
Service successfully installed.
D:\devServer\mysql-8.0.22-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
D:\devServer\mysql-8.0.22-winx64\bin>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
D:\devServer\mysql-8.0.22-winx64\bin>mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
D:\devServer\mysql-8.0.22-winx64\bin>mysql -u root -P P-)Jz2vih:3;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
D:\devServer\mysql-8.0.22-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.22
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> alter user 'root@localhost' identified by '123456';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.04 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
mysql>
命令:
初始化数据库(要注意记住初始化的临时密码):mysqld —initialize —console
安装到本地服务(服务名称默认为 mysql):mysqld —install
启动本地服务:net start mysql
需要修改密码,登录 mysql,执行命令,刷新权限:
mysql -u root -p
alter user ‘root@localhost’ identified by ‘123456’;
FLUSH PRIVILEGES;
exit
完成安装,快来使用工具连接一下 mysql 服务吧!