Windows10系统安装双版本MySQL详细教程

背景:windows10服务器上以前项目一直用的MySQL5.5,现在项目需要用MySQL8,为了不影响以前的项目(版本直接有很多不兼容的地方),打算安装两个MySQL

1、下载mysql-8.0.17-winx64.zip

链接:https://pan.baidu.com/s/1eo8biZIBK-xR2cCWAeAYkw 
提取码:82ix

2、解压后放入随便一个盘,我放F:\MySQL8目录下

 

完整路径:F:\MySQL8\mysql-8.0.17-winx64
在F:\MySQL8\mysql-8.0.17-winx64路径下新加my.ini文件
内容:
[mysqld]
port=3307
basedir=F:\MySQL8\mysql-8.0.17-winx64
datadir=F:\MySQL8\mysql-8.0.17-winx64\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set=utf8

 3、以管理员身份去运行命令行窗口

C:\Windows\system32>F:

F:\>cd MySQL8

F:\MySQL8>cd mysql-8.0.17-winx64/bin

F:\MySQL8\mysql-8.0.17-winx64\bin>mysqld install mysql8 --default-file="F:\MySQL8\mysql-8.0.17-winx64\my.ini"

成功安装后会提示:
Service successfully installed.

4、去服务里面,可查看到此时多了一个mysql8服务

5、初始化数据库

mysql服务安装成功后,就需要初始化数据库了,否则是无法启动服务的。

在bin目录下执行如下命令

F:\MySQL8\mysql-8.0.17-winx64\bin>mysqld --initialize

然后稍等片刻:文件夹中会自动生成data目录

6、打开注册表,找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mysql8,修改ImagePath参数,更正mysql8服务相关路径。

win+R,输入regedit,打开注册表

7、启动数据库,修改密码

F:\MySQL8\mysql-8.0.17-winx64\bin>net start mysql8
mysql8 服务正在启动 ..
mysql8 服务已经启动成功。
F:\MySQL8\mysql-8.0.17-winx64\bin>mysql -P3307 -uroot -p
Enter password:这里的密码从F:\MySQL8\mysql-8.0.17-winx64\data\***.err获取
找到temporary password is generated for root@localhost: =*KuaCxQX4nd
后面的 =*KuaCxQX4nd 就是临时密码(不包括空格)
F:\MySQL8\mysql-8.0.17-winx64\bin>mysql -P3307 -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>ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
Query OK, 0 rows affected (0.12 sec)

mysql> quit
Bye

8、新加用户,设置远程连接

F:\MySQL8\mysql-8.0.17-winx64\bin>mysql -P3307 -uroot -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.17 MySQL Community Server - GPL

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

mysql> CREATE USER 'newuser'@'%' IDENTIFIED BY 'newuserpassword';
Query OK, 0 rows affected (0.10 sec)

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

mysql> GRANT ALL ON *.* TO 'newuser'@'%';
Query OK, 0 rows affected (0.13 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
mysql> ALTER USER 'newuser'@'%' IDENTIFIED WITH mysql_native_password BY 'newuserpassword';
Query OK, 0 rows affected (0.08 sec)

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

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.07 sec)

mysql>

9、截图:

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小达哥的垃圾桶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值