如何使用Liquibase创建数据库

8
  • I am trying to use Liquibase to create database that does not exists.
  • I have downloaded MySQL and not made any change in it

  • My maven plugin code looks like

    <plugins>
        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <changeLogFile>src/main/resources/changelog.xml</changeLogFile>
                <driver>com.mysql.jdbc.Driver</driver>
                <url>jdbc:mysql://localhost:3306/myApp?createDatabaseIfNotExist=true</url>
            </configuration>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    
当我运行mvn clean install时,出现如下错误:
Failed to execute goal org.liquibase:liquibase-maven-plugin:3.1.1:update (default) on project database_seed: Error setting up or running Liquibase: liquibase.exception.DatabaseException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'myApp' -> [Help 1]

如何解决这个问题?

如果没有其他办法,您可能需要考虑在变更集中使用<sql>创建模式。 - Alexey Malev
如果有人正在寻求如何通过Liquibase创建新的MySQL模式的帮助,则此问题将结束我们的搜索。以下的createDatabaseIfNotExist=true可以达到这个目的。jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true - Aԃιƚყα Gυɾαʋ
1个回答

10

看起来您在配置中没有传递用户名或密码:

(来自Liquibase Maven文档)

<configuration>
  <changeLogFile>src/main/resources/changelog.xml</changeLogFile>
  <driver>com.mysql.jdbc.Driver</driver>
  <url>jdbc:mysql://localhost:3306/myApp?createDatabaseIfNotExist=true</url>
  <username>liquibaseTest</username>
  <password>pass</password>
</configuration>

2
如果您在Spring Boot中使用application.properties进行配置,请使用以下键值对:spring.datasource.url= jdbc:mysql://localhost:11030/myAppcreateDatabaseIfNotExist=truespring.datasource.username=liquibaseTest spring.datasource.password=pass - realPK

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接