欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

解决Windows环境下安装 mysql-8.0.11-winx64 遇到的问题

程序员文章站 2022-07-20 18:02:09
下载mysql安装包,我的是下载mysql-8.0.11-winx64,解压到你想安装的目录下,然后配置环境(window环境下,mac本还没试过), 1、首先,配置环境...

下载mysql安装包,我的是下载mysql-8.0.11-winx64,解压到你想安装的目录下,然后配置环境(window环境下,mac本还没试过),

1、首先,配置环境:右击此电脑->属性->高级系统设置->环境变量->path->新建 ,然后将自己的路径添加进去(例如我目录:f:\mysql\mysql-8.0.11-winx64),除此之外还要看解压的压缩包内是否有my.ini文件或者my-default.ini文件,如果没有需要自己写一个在根目录下,默认的配置信息如下:

查看所有的配置项,可参考:

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=f:\mysql\mysql-8.0.11-winx64
# 设置mysql数据库的数据的存放目录(此目录会在之后进行命令生成,无需手写)
datadir=f:\mysql\mysql-8.0.11-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为utf8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=innodb
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

2、然后打开终端,window+r 然后输入cmd 打开终端并切换到该路径下,并执行命令 mysqld --initialize 检查当前环境,如果没有任何报错,打开你的目录你会看到你的根目录会出现data文件夹;说明一切正常

解决Windows环境下安装 mysql-8.0.11-winx64 遇到的问题

注意这一步可能会遇到一些报错信息,例如弹出“ 由于找不到vcruntime140.dll,无法继续执行代码,重新安装程序可能会解决此问题 ”等问题,说明你的电脑缺少一些必要的文件,这时要打开控制面板查看c++ 2015具体信息,

 解决Windows环境下安装 mysql-8.0.11-winx64 遇到的问题

我的是因为之前没有x64位的c++,所以缺少文件,如果你的有,那么可点击卸载,它会提示你让你进行修复,点击修复,完成,就可以继续在终端输入命令;

初始化数据库

mysqld --initialize --console

这时会打印如下error,意思是已经有了data目录了,只要把他删除就好,

f:\mysql\mysql-8.0.11-winx64\bin>mysqld --initialize --console
2018-10-29t09:26:35.244245z 0 [system] [my-013169] [server] f:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 980
2018-10-29t09:26:35.287469z 0 [error] [my-010457] [server] --initialize specified but the data directory has files in it. aborting.
2018-10-29t09:26:35.299110z 0 [error] [my-010119] [server] aborting
2018-10-29t09:26:35.302159z 0 [system] [my-010910] [server] f:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe: shutdown complete (mysqld 8.0.11)  mysql community server - gpl.

再次执行上面命令,会打印用户的初始密码,其中@localhost : xxxxxx就是默认密码,需要记住,如果没有记住,就将后来生成的data文件删除,再次生成也是可以的

f:\mysql\mysql-8.0.11-winx64\bin>mysqld --initialize --console
2018-10-29t09:28:49.177043z 0 [system] [my-013169] [server] f:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 12980
2018-10-29t09:29:19.270535z 5 [note] [my-010454] [server] a temporary password is generated for : kw3alny_g.dg
2018-10-29t09:29:41.684599z 0 [system] [my-013170] [server] f:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed

3、然后安装服务, mysqld --install[服务名] 如果只有一个服务可以不写默认mysql,如果多个服务可以写具体的服务名称,xxxx,当回车之后,又出现错误, install/remove of the service deined,这是由于运行cmd的时候不是用管理员的身份运行的,只要再次以管理员的命令运行cmd就可以了,出现service successfully installed 说明服务安装好了。

f:\mysql\mysql-8.0.11-winx64\bin>mysqld --install
service successfully installed.

4、启动服务,运行命令 : net start mysql ,看到服务已经启动成功

f:\mysql\mysql-8.0.11-winx64\bin>net start mysql
mysql 服务正在启动 ....
mysql 服务已经启动成功。

5、更改密码和密码认证插件 ,

在mysql安装目录的 bin 目录下执行命令:mysql -u root -p

f:\mysql\mysql-8.0.11-winx64\bin>mysql -u root -p
enter password: *******
error 1045 (28000): access denied for user 'root'@'localhost' (using password: yes)

这时要重新生成密码,删除data目录,运行mysqld --initialize --console,

f:\mysql\mysql-8.0.11-winx64\bin>mysqld --initialize --console
2018-10-29t10:04:23.337650z 0 [system] [my-013169] [server] f:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 7928
2018-10-29t10:05:19.210237z 5 [note] [my-010454] [server] a temporary password is generated for root@localhost: rxzg!fjr2ly+
2018-10-29t10:06:00.603070z 0 [system] [my-013170] [server] f:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed

重新执行mysql -u root -p,填入密码(注意密码左右没有空格),这时会打印出相关的信息

f:\mysql\mysql-8.0.11-winx64\bin>mysql -u root -p
enter password: ************
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 8
server version: 8.0.11

copyright (c) 2000, 2018, 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 identified with mysql_native_password by '新密码';,出现下面情况就证明你已经修改成功。

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '5502yulijian.';
query ok, 0 rows affected (0.17 sec)

show databases; (‘;'一定要加)

解决Windows环境下安装 mysql-8.0.11-winx64 遇到的问题

这样就可以了

总结

以上所述是小编给大家介绍的解决windows环境下安装 mysql-8.0.11-winx64 遇到的问题,希望对大家有所帮助