MySQL 8 安装及初始化(Windows版)

本文详细介绍了如何在Windows上安装MySQL 8.0,包括从下载到解压,添加环境变量,安装过程,特别是初始化数据库和设置初始密码。此外,还解决了MySQL 8的远程连接配置和特定版本的认证问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载

https://dev.mysql.com/downloads/mysql/

解压

路径D:\dev\mysql-8.0.30-winx64;

添加环境变量

D:\dev\mysql-8.0.30-winx64\bin添加到环境变量
在这里插入图片描述

安装

使用管理员方式打开cmd (命令窗口输入输入cmd后 输入Ctrl+Shift+Enter)

开始安装

(1)、mysqld install

C:\Windows\system32>mysqld install
Service successfully installed.

(2)、启动服务 net start mysql
出现错误先忽略

C:\Windows\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。
服务没有报告任何错误。

(3)初始化 mysqld --initialize --console
如下命令得到的初始密码是U,l&FF/!l0dz

C:\Windows\system32>mysqld --initialize --console
2022-08-31T01:25:52.873437Z 0 [System] [MY-013169] [Server] D:\dev\mysql-8.0.30-winx64\bin\mysqld.exe (mysqld 8.0.30) initializing of server in progress as process 29564
2022-08-31T01:25:52.887789Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-31T01:25:53.125133Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-31T01:25:53.719896Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: U,l&FF/!l0dz

(4)、修改默认密码
如果服务未启动成功,则再次执行net start 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.30
。。。
mysql> ALTER USER USER() IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

远程链接

配置

进入mysql后
update user set host = ‘%’ where user = ‘root’;
重启服务

mysql> use mysql
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql8特殊处理

mysql8版本会提示“Navicat连接Mysql 8.0报错并显示:Client does not support authentication protocol requested by server”
问题原因:Mysql8.0的默认认证方式改用sha2了,要么升级客户端,要么修改要登陆的用户认证方式
下面只讲解修改认证方式方案;

解决方法:
alter user ‘root’@‘%’ IDENTIFIED WITH mysql_native_password by ‘123456’;
flush privileges;

mysql> select host,user ,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> alter user 'root'@'%' IDENTIFIED WITH mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user ,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值