解决:mybatis-generator-maven-plugin:1.3.2:generateAccess denied for user 'root'@'localhost'

时光怂恿深爱的人放手 提交于 2020-03-17 18:52:50

问题描述
Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project springboot_v2: Access denied for user ‘root’@‘localhost’ (using password: YES)

Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project springboot_v2: Access denied for user 'root'@'localhost' (using password: YES)

可能原因

1、root用户没有权限访问该数据库并进行表的增删改查操作

解决方案

修改root用户在该数据库的权限,即添加相应权限
在navicat中新建查询执行以下代码

GRANT Alter, Alter Routine, Create, Create Routine, Create Temporary Tables, Create View, Delete, Drop, Event, Execute, Grant Option, Index, Insert, Lock Tables, References, Select, Show View, Trigger ON `springbootv2`.* TO `root`@`localhost`;

springbootv2是数据库的名字,这里需要填你自己的数据库。
图形化界面如对相应数据库添加用户权限即可。
在这里插入图片描述

2、pom文件中,mybatis.generator插件的配置文件目录错误。

解决方案

generator.xml文件的位置正确填写在pom文件中

示例
配置文件路径
在这里插入图片描述

		<!-- generator 配置-->
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.7</version>
				<configuration>
					<!--允许移动生成的文件 -->
					<verbose>false</verbose>
					<!--允许覆盖生成的文件 -->
					<overwrite>false</overwrite>
					<!--配置文件的路径 -->
					<configurationFile>src/main/resources/generator/MyBatisGenerator/generator.xml</configurationFile>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>${mysql.version}</version>
					</dependency>
				</dependencies>
			</plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!