MySQL安装教程
第一步:MySQL官方网址:https://dev.mysql.com/downloads/mysql/
第二步:建议解压MySQL集成包到D盘目录下或者其它盘目录下,最好不要在C盘
第三步:配置MySQL
配置初始化的my.ini文件的文件
解压后的目录并没有的my.ini文件,没关系可以自行创建在安装根目录下添加的my.ini(新建文本文件,将文件类型改为的.ini),写入基本配置:
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录 【注意】需要改成自己的MySQL目录下
basedir=C:\mysql-8.0.26-winx64
# 设置mysql数据库的数据的存放目录
datadir=C:\mysql-8.0.26-winx64\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
# SQL模式
sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
第四步:以管理员的身份运行cmd
第五步:切换到MySQL的目录下
注意:博主的电脑只有一个C盘,就不用切换盘符了
切换盘符命令
C:\WINDOWS\system32>D:
再切换到自己的MySQL安装的bin目录
cd mysql-8.0.26-winx64\bin
第六步:生成MySQL临时密码
mysqld --initialize --console
注意![注意] [MY-010454] [服务器]为root @ localhost生成临时密码(pgpGZoSs&4.S)在没有更改密码前,需要记住这个密码,后续登录需要用到。复制密码先保存起来!!!
第七步:安装MySQL服务
安装命令
mysqld --install
代表安装成功
Service successfully installed.
第八步:启动MySQL服务
net start mysql
代表启动成功
C:\mysql-8.0.26-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
第九步:登录MySQL
C:\mysql-8.0.26-winx64\bin>mysql -u root -p --登录命令
Enter password: ************ --第六步:生成MySQL临时密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.26
Copyright (c) 2000, 2021, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY '0620';
Query OK, 0 rows affected (0.01 sec) --修改成功
第十一步:退出重新登录使用修改过的密码
mysql> exit --退出命令
Bye
C:\mysql-8.0.26-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.26 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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_HOME
变量值:MySQL根目录
第十三步:添加Path
%MYSQL_HOME%\bin
第十四步:结束MySQL进程
第十五步:通过配置环境变量可以直接启动MySQL服务,无需切换盘符和路径
C:\WINDOWS\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
C:\WINDOWS\system32>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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.