不卸载原有mysql直接安装mysql8.0

吾爱主题 阅读:139 2023-05-29 11:18:00 评论:0

下载zip安装包

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

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

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

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [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目录执行命令:

?
1 mysqld --initialize --console

此时,我的win7系统报错:

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

我使用的下载地址:http://www.tuohang.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:

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

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

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

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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:

?
1 2 3 4 5 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目录执行命令:

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

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

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

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

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

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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。

删除服务:

?
1 sc delete mysql8.0 -remove

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

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

原文链接:https://xxmdmst.blog.csdn.net/article/details/113204880

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容