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>
    

When I run mvn clean install, I see error as

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]

How do I fix it?

daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • You may want to consider creating schema using in changeset. If nothing else helps. – Alexey Malev May 19 '14 at 19:22
  • If someone is searching help on how to create fresh MySQL schema through liquibase then this question ends our search. Following createDatabaseIfNotExist=true serves the purpose. jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true – Aԃιƚყα Gυɾαʋ Jul 19 '22 at 11:41

1 Answers1

10

Looks like you're not passing a username or password as part of your config:

(from the liquibase maven documentation)

<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>
hd1
  • 33,938
  • 5
  • 80
  • 91
matt
  • 9,113
  • 3
  • 44
  • 46
  • 2
    If you are using application.properties for configuration in spring-boot, please use the key-value pairs below: `spring.datasource.url= jdbc:mysql://localhost:11030/myAppcreateDatabaseIfNotExist=true` `spring.datasource.username=liquibaseTest` `spring.datasource.password=pass` – realPK Oct 12 '16 at 19:07