本文以mysql-8.0.22 zip版为例进行配置,进入官网。
一、下载
mysql-8.0.X-winx64下载
将下载好的文件解压到指定目录,小编解压到D:\installsoft\mysql
二、配置环境变量
1、在系统环境变量中“新建”一个名为“MYSQL_HOME”的变量。变量值:D:\installsoft\mysql
2、编辑现有的系统环境变量“Path”,新建“%MYSQL_HOME%\bin”。
三、配置初始化my.ini
在mysql根目录中新建my.ini文件,内容如下:
[mysqld]
#设置mysql的安装目录
basedir = D:\\installsoft\mysql
#设置mysql数据库的数据的存放目录
datadir = D:\\installsoft\mysql\data
#设置端口
port = 3306
#允许最大连接数
max_connections=200
#允许连接失败的次数。防止有人从该主机试图攻击数据库系统
max_connect_errors=10
#服务端使用的字符集默认为UTF8MB4
character-set-server=utf8mb4
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
#设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
四、初始化数据库
以管理员身份运行cmd命令,并将路径换到mysql的bin目录下,运行命令
mysqld --initialize --console
看到 initializing of server has completed,表示初始化完成。
其中倒数第2句要粘贴到记事本上,以防忘记,后面是默认密码
A temporary password is generated for root@localhost: Hq4ybg7IHs<Z
提示:如果你关了这个窗口,或者没记住,那也没事,删掉初始化的 data 目录(就是解压文件夹下的data文件夹)里面的东西,不要删除data文件夹,再执行一遍初始化命令,又会重新生成的。
五、安装服务
注意一定要使用管理员提示符进入。
在bin目录下输入如下命令(mysqld –install [服务名] 其中服务名可以不写,默认是Mysql )
mysqld -install
显示Service successfully installed.安装完成。
六、启动服务
输入命令
net start mysql
七、登录数据库并修改密码
登录数据库:
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17
Copyright (c) 2000, 2019, 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>
重新设置root密码(红色部分密码自行修改)
alter user 'root'@'localhost' identified by 'Dongyun@8888' password expire never;
use mysql;
update user set host = '%' where user = 'root';
至此安装完成!
修改加密规则(可能会报ERROR 1396 (HY000): Operation ALTER USER failed for ‘root’@’%’,再执行一次即可!)
ALTER USER 'root'@'%' IDENTIFIED BY 'Dongyun@8888' PASSWORD EXPIRE NEVER;
更新 root 用户密码(允许navicat登录)
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Dongyun@8888';
刷新权限
FLUSH PRIVILEGES;
附:卸载并删除MySQL
1、停止MySQL服务
开始→所有应用→Windows管理工具→服务,将MySQL服务停止。
2、在cmd中输入sc delete Mysql将服务删除,显示[SC] DeleteService 成功。
3、将MySQL安装目录下的MySQL文件夹删除(我的安装目录是C:\Program Files (x86)\MySQL)
4、运行“regedit”文件,打开注册表,计算机\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\Application\
删除MySQLD Service文件夹
评论前必须登录!
注册