通过zip方式安装mysql服务
Mysql安装包下载
通过访问mysql官网下载:mysql下载地址
mysql安装及环境配置
1.解压缩
下载完成后,解压到合适的安装位置:E:\servers\mysql-8.0.37-winx64
配置环境变量
复制解压的位置,来配置环境变量
右键此电脑->属性->高级系统设置->高级->环境变量->新建系统变量
- 新建MYSQL_HOME
- 新增PATH配置(本来就有) %MYSQL_HOME%\bin
初始化mysql配置
-
配置文件:在mysql安装路径下新建文件my.ini进行一些默认配置,注意basedir是mysql安装位置,datadir是数据存放地址,可以手动新建data文件夹
[client]
port=3306
default-character-set=utf8
[mysqld]
bind-address=127.0.0.1
skip-networking=0
basedir=E:/servers/mysql-8.0.37-winx64
datadir=E:/servers/mysql-8.0.37-winx64/data
port=3306
character_set_server=utf8mb4
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
explicit_defaults_for_timestamp=true -
通过管理员权限启动cmd:
mysqld --initialize --user=mysql --console
**注意在输出的最后一行提供了mysql的初始密码不要忘了保存
我的是7hgRquaQkM)n **C:\Windows\System32>mysqld --initialize --user=mysql --console
2024-10-08T01:40:50.701999Z 0 [System] [MY-013169] [Server] E:\servers\mysql-8.0.37-winx64\bin\mysqld.exe (mysqld 8.0.37) initializing of server in progress as process 15404
2024-10-08T01:40:50.715118Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-10-08T01:40:50.993325Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-10-08T01:40:51.990600Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7hgRquaQkM)n
安装mysql服务
继续在cmd窗口输入命令mysqld --install
C:\Windows\System32>mysqld --install
Service successfully installed.
启动MySQL服务
看到上面的安装成功提示就可以启动了,继续在cmd窗口键入:net start mysql
C:\Windows\System32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
连接mysql
看到启动成功提示,输入命令 mysql -u root -p
然后输入刚才的密码
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.37
Copyright (c) 2000, 2024, 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用户密码
成功进入mysql命令行后,在mysql>命令行输入命令alter user root@localhost identified by 'root';
mysql> alter user root@localhost identified by 'root';
Query OK, 0 rows affected (0.02 sec)
mysql>
密码就被修改为root了 下次登陆使用新密码就可以了