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

MySQL安装Win10安装图文详解,备忘笔记

程序员文章站 2022-05-29 16:24:57
...


[MY-013236] [Server] The designated data directory C:/myProviderSource/mysql_file/mysql-8.0.21-winx64/data is unusable. You can remove all files that the server added to 解决方案

1、浏览器搜索mysql下载安装

地址:https://dev.mysql.com/downloads/mysql/.
MySQL安装Win10安装图文详解,备忘笔记

2、直接下载

MySQL安装Win10安装图文详解,备忘笔记

3、下载压缩包,直接解压缩,没有相关文件就直接新建

MySQL安装Win10安装图文详解,备忘笔记

4、新建my.ini文件

[client]
# Set the default port for mysql client to connect to the server
port=3306
[mysql]
# Set the mysql client default character set
default-character-set=utf8
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this. you step dir
basedir=C:/myProviderSource/mysql_file/mysql-8.0.21-winx64
#Path to the database root you db data store dir  **可以不指定会自动生成**
datadir=C:/myProviderSource/mysql_file/mysql-8.0.21-winx64/data
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict    delele ONLY_FULL_GROUP_BY
# sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# The maximum amount of concurrent sessions the MySQL server will allow. 
max_connections=200
# The num of connection failures allowed 防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# Myaql_native_pasaword plug-in authentication is used by default 默认使用 mysql_native_password 插件认证
default_authentication_plugin=mysql_native_password

5、配置mysql的bin目录进系统环境变量path

右击此电脑->属性->高级系统设置->环境变量->path ,然后将自己的路径添加进去
MySQL安装Win10安装图文详解,备忘笔记

6、然后打开终端,

右击开始->windows系统->命令提示符->右击以管理员运行->cd到mysql的bin目录下,并执行命令 mysqld --initialize(会生成xxx.err文件)或者mysqld --initialize --console(不会生成xxx.err文件直接在终端输出) 检查当前环境,如果没有任何报错,打开你的目录你会看到你的根目录会出现data文件夹说明一切正常、 若出现:

F:\mysql\mysql-8.0.21-winx64\bin>mysqld --initialize --console
20-10-29T09:26:35.244245Z 0 [System] [MY-013169] [Server] F:\mysql\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.21) initializing of server in progress as process 980
20-10-29T09:26:35.287469Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
20-10-29T09:26:35.299110Z 0 [ERROR] [MY-010119] [Server] Aborting
意思是已经有了data目录了,你可以删除目录再次执行命令

正确需要的是加粗部分密码,后边登录用:
[Server] A temporary password is generated for aaa@qq.com: Mw3AlnY+g&ky

7、安装服务mysqld --install[服务名]

如果只有一个服务可以不写默认mysql,如果多个服务可以写具体的服务名称 XXXX(出现错误 install/remove of the service deined 是由于运行cmd的时候不是用管理员的身份运行的),出现service successfully installed 说明服务安装好了

F:\mysql\mysql-8.0.21-winx64\bin>mysqld --install
Service successfully installed.

8、启动服务,运行命令 : net start mysql

看到服务已经启动成功

F:\mysql\mysql-8.0.21-winx64\bin>net start mysql
MySQL 服务正在启动 …
MySQL 服务已经启动成功

9、修改MYSQL登录密码

1、执行命令:mysql -u root -p

F:\mysql\mysql-8.0.21-winx64\bin>mysql -u root -p
Enter password: *******
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

1.1、这时要重新生成密码,删除data目录,运行mysqld --initialize --console,重复上边步骤

F:\mysql\mysql-8.0.21-winx64\bin>mysqld --initialize --console
20-10-29T10:05:19.210237Z 5 [Note] [MY-010454] [Server] A temporary password is generated for aaa@qq.com: RvtG!cfgbLy+

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

F:\mysql\mysql-8.0.21-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.21
Copyright © 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.

2、修改用户密码,在MySQL中执行:alter user aaa@qq.com identified by ‘root’; enter键后成功改密码为root,这里sql语句后面的分号不要丢,出现下面情况就证明你已经修改成功。

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED [WITH mysql_native_password] BY ‘你的密码’;
Query OK, 0 rows affected (0.17 sec)

嘿嘿!大功告成

关于sql_mode这个报错,就是因为group by字段必须完全显示在查询列里,所以去掉这个模式就好了

Caused by: java.sql.SQLSyntaxErrorException: Expression #13 of SELECT list is not in GROUP BY clause and contains nonaggregated column ...........which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

MySQL安装Win10安装图文详解,备忘笔记
更多详情:https://www.jb51.net/article/149875.htm