1.下载mysql zip包并解压到指定目录:
下载地址:https://dev.mysql.com/downloads/mysql/(一般下载第一个链接,如文件名称:mysql-8.0.32-winx64.zip)
2.配置环境变量(我的电脑右键属性->高级系统设置->环境变量):
在系统变量下点击新建
变量名称为MYSQL_HOME,变量值为自己刚才解压后的目录位置,如:D:\datastorage\mysql-8.0.32-winx64
3.在系统变量里找到path进行编辑
在最后面新增:%MYSQL_HOME%\bin
4.在解压目录(如:D:\datastorage\mysql-8.0.32-winx64)新建my.ini或my-default.ini文件
ini文件内容如下:
[mysql]
# 设置mysql客户端默认字符集
# default-character-set=utf8
default-character-set=utf8mb4
[mysqld]
# 绑定IPv4
# bind-address=0.0.0.0
#bind-address=127.0.0.1
# 设置端口号
port=13306
# 设置mysql的安装目录,即解压目录
basedir=D:\\datastorage\\mysql-8.0.32-winx64
# 设置数据库的数据存放目录
datadir=D:\\datastorage\\mysql-8.0.32-winx64\\data
# 设置允许最大连接数
max_connections=200
# 设置允许连接失败次数
max_connect_errors=10
# 设置服务端的默认字符集
# character-set-server=utf8
character-set-server=utf8mb4
#character_set_database=utf8mb4
#character_set_system=utf8mb4
#collation_connection=utf8mb4_unicode_ci
#collation_server=utf8mb4_unicode_ci
# 创建表使用的默认存储引擎
default-storage-engine=INNODB
# 使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
#解决This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
log-bin-trust-function-creators=1
max_allowed_packet=1024M
wait_timeout=288000
interactive_timeout = 288000
secure_file_priv =
ini内配置的端口等根据自己需求修改,其中,datadir和basedir文件夹的路径可以根据个人喜好配置(尽量不使用中文),没有datadir中data目录,需手动创建一个目录(没有data目录,有可能会报错),保证此目录为空,不能包含任何文件
5.cmd用管理员身份进入D:\datastorage\mysql-8.0.32-winx64\bin目录,命令如:
C:\Windows\System32>d:
D:\>cd D:\datastorage\mysql-8.0.32-winx64
D:\datastorage\mysql-8.0.32-winx64> cd bin
D:\datastorage\mysql-8.0.32-winx64\bin>
6.安装服务命令:mysqld -install mysql8032 --defaults-file=D:\datastorage\mysql-8.0.32-winx64\my.ini,执行后如下:
D:\datastorage\mysql-8.0.32-winx64\bin>mysqld -install mysql8032 --defaults-file=D:\datastorage\mysql-8.0.32-winx64\my.ini
Service successfully installed.
D:\datastorage\mysql-8.0.32-winx64\bin>
7.进行mysql的初始化:
mysqld --initialize --console
执行后如下:
D:\datastorage\mysql-8.0.32-winx64\bin>mysqld --initialize --console
2023-03-28T01:53:36.578461Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-03-28T01:53:36.578743Z 0 [System] [MY-013169] [Server] D:\datastorage\mysql-8.0.32-winx64\bin\mysqld.exe (mysqld 8.0.32) initializing of server in progress as process 16332
2023-03-28T01:53:36.724235Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-03-28T01:53:43.447654Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-03-28T01:53:48.119291Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vFTvoYp7?_39
此时要记住自己的初始化密码:vFTvoYp7?_39
8.启动服务:
D:\datastorage\mysql-8.0.32-winx64\bin>net start mysql8032
mysql8032 服务正在启动 ..
mysql8032 服务已经启动成功。
D:\datastorage\mysql-8.0.32-winx64\bin>
9.使用root登录:
登录密码为上面第7步初始化的密码 vFTvoYp7?_39 ,执行如下:
D:\datastorage\mysql-8.0.32-winx64\bin>mysql -uroot -P13306 -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32
Copyright (c) 2000, 2023, 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>
10.修改root密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql82023';
执行后如下:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql82023';
Query OK, 0 rows affected (0.04 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql>
11.设置远程登录:
mysql8.0之前,创建一个mysqla用户,允许所有IP访问,密码是mysql82023
GRANT ALL PRIVILEGES ON *.* TO 'mysqla'@'%' IDENTIFIED BY 'mysql82023' WITH GRANT OPTION;
但是从MySQL8版本开始,不能再使用GRANT创建用户,而是要先CREATE USER,然后使用GRANT授权
CREATE USER 'mysqla'@'%' IDENTIFIED BY 'mysql82023';
GRANT ALL PRIVILEGES ON *.* TO 'mysqla'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
执行后如下:
mysql> CREATE USER 'mysqla'@'%' IDENTIFIED BY 'mysql82023';
Query OK, 0 rows affected (0.03 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysqla'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql>
12使用新创建的用户登录:
先退出root账号登录,执行后如下:
mysql> exit;
Bye
D:\datastorage\mysql-8.0.32-winx64\bin>mysql -umysqla -P13306 -p
Enter password: **************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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>
备注,使用root用户远程链接:
mysql8.0 root 开启远程访问
修改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql82023';
创建root远程用户:
CREATE USER 'root'@'%' IDENTIFIED BY 'mysql82023';
GRANT ALL ON *.* TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'mysql82023';
FLUSH PRIVILEGES;
13.到此步骤即可使用工具进行数据库连接了,仅为安装方便做个记录。