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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_31122833/article/details/100511463

背景: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、截图:

猜你喜欢

转载自blog.csdn.net/qq_31122833/article/details/100511463