如何在不卸载现有mysql的情况下安装mysql8.0?

如何在不卸载现有mysql的情况下安装mysql8.0?

下载zip安装包

下载地址:https://dev.mysql.com/downloads/mysql/

下载完成后,解压压缩包,进入压缩的目录,新建文本文件my.ini。

假设你解压出来的目录为E:\Program Files\mysql-8.0.19-winx64,my.ini内容如下:

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=E:\Program Files\mysql-8.0.19-winx64
# 设置mysql数据库的数据的存放目录
datadir=E:\Program Files\mysql-8.0.19-winx64\data   
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=UTF8MB4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=UTF8MB4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=UTF8MB4

初始化数据库

在MySQL安装目录的bin目录执行命令:

mysqld --initialize --console

此时,我的win7系统报错:

image-20200607003323063

解决方案:去百度下载一个vcruntime140_1.dll放入%windir%\system32\目录中。

我使用的下载地址:https://www.jb51.net/dll/vcruntime140_1.dll.html

%windir%\system32\在我的系统中表示C:\Windows\System32

再次执行上述命令后:

E:\Program Files\mysql-8.0.19-winx64\bin>mysqld --initialize --console
2020-06-06T16:34:34.062007Z 0 [System] [MY-013169] [Server] E:\Program Files\mys
ql-8.0.19-winx64\bin\mysqld.exe (mysqld 8.0.19) initializing of server in progre
ss as process 7816
2020-06-06T16:34:37.513202Z 5 [Note] [MY-010454] [Server] A temporary password i
s generated for root@localhost: /rfMQ+bGi22z

表示初始化成功。

注意:我这里生成的临时密码是/rfMQ+bGi22z,下文会使用到。

登陆mysql数据库

启动mysql服务端,需要另外启动一个命令后,执行mysqld:

E:\Program Files\mysql-8.0.19-winx64\bin>mysqld

image-20200607004704811

就如上图一样,让这个命令行一直后台挂着,mysql的服务进程占用着它,不能关闭,关闭后mysql的服务进程也会跟着被关闭。

再用mysql客户端登陆后,顺利登陆:

E:\Program Files\mysql-8.0.19-winx64\bin>mysql -uroot -p/rfMQ+bGi22z
mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

Copyright (c) 2000, 2020, 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>

修改密码为123456:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1
23456';
Query OK, 0 rows affected (0.01 sec)

mysql>

注册/删除mysql服务

经过上述操作mysql8.0已经可以正常使用,但启动mysql服务需要占用一个命令行未免有些麻烦,现在我们通过将mysqld注册为系统服务解决这个问题。

在MySQL安装目录的bin目录执行命令:

E:\Program Files\mysql-8.0.19-winx64\bin>mysqld --install mysql8.0
Service successfully installed.

mysql8.0可以改为其他你喜欢的服务的名字。

注册成功后,任务管理器上可以看到服务的名字:

image-20200607005626027

只需要右键启动服务,mysql8.0就可以正常使用了。

然后mysql客户端就可以使用新密码正常的登陆了:

E:\Program Files\mysql-8.0.19-winx64\bin>mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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>

如果你希望在任何目录下都能执行mysql客户端命令,则需要将mysql的安装目录下的bin目录加入环境变量中,例如:E:\Program Files\mysql-8.0.19-winx64\bin。

删除服务:

sc delete mysql8.0 -remove

mysql8.0是你要删除的服务名称

到此这篇关于不卸载原有mysql直接安装mysql8.0的文章就介绍到这了,更多相关安装mysql8.0内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

若文章对您有帮助,帮忙点个赞!

0
0
发布时间 2023-05-22 09:32:33
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)