MySQL and Postgresql installation help needed

I have Python project that I must use MySql community or Postgresql. But the software of this database tools are not working in IDX project, is it possible to use the extension in vs code extensions instead of the software or any alternative method?

Hi @AB_Anu

Currently PostgreSQL still cannot be run as a service. but it is still possible if run manually.

Does MySQL 8.0 not meet your needs?

Now we can install MySQL 8.0 on IDX. just add services.mysql on your dev.nix file:

  packages = [
    ...
  ];

  # See: https://nixos.wiki/wiki/Mysql
  services.mysql = {
    enable = true;
    package = pkgs.mysql80;
  };

  # Sets environment variables in the workspace
  env = {};

Or you can watch this video for a step-by-step guide.

Hi @arifnd . After installing MySQL in IDX, how can we connect our local database to a project in IDX? Is it possible?

Hi @vinay_kumar,

Is importing data from local to the database in the workspace not possible? or because of security?

So far I haven’t thought about having to access a local database.

Hi @arifnd , I have set up a Spring Boot Maven Java project in project idx , but I am facing issues connecting to my local database. Do you know how to connect it, or is there any way to connect the database to the project?

I have never used Spring Boot Maven Java. Can you share the error message and your dev.nix configuration? Thanks.

yeah sure, below are the file and error message
dev.nix file

# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
  # Which nixpkgs channel to use.
  channel = "stable-23.11"; # or "unstable"
  # Use https://search.nixos.org/packages to find packages
  packages = [
    pkgs.jdk17
    pkgs.maven
  ];
  services.mysql = {
    enable = true;
    package = pkgs.mysql80;
  };
# services.jdbc = {
#   enable = true;
#   package = pkgs.jdbc;
# };

  # Sets environment variables in the workspace
  env = {};
  idx = {
    # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
    extensions = [
      # "vscodevim.vim"
      "redhat.java"
      "vscjava.vscode-java-debug"
      "vscjava.vscode-java-dependency"
      "vscjava.vscode-java-pack"
      "vscjava.vscode-java-test"
      "vscjava.vscode-maven"
      "Pivotal.vscode-boot-dev-pack"
      "vmware.vscode-spring-boot"
      "vscjava.vscode-spring-boot-dashboard"
      "vscjava.vscode-spring-initializr"
    ];
    # Enable previews
    previews = {
      enable = true;
      previews = {
        web = {
          # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
          # and show it in IDX's web preview panel
          command = ["./gradlew" ":bootRun" "--args='--server.port=$PORT'"];
          manager = "web";
        };
      };
    };
    # Workspace lifecycle hooks
    workspace = {
      # Runs when a workspace is first created
      onCreate = {
        # Example: install JS dependencies from NPM
        # npm-install = 'npm install';
      };
      onStart = {
        # Example: start a background task to watch and re-build backend code
        # watch-backend = "npm run watch-backend";
      };
    };
  };
}

Error Message
2024-06-07T07:06:16.787Z ERROR 12355 — [springboot-blog-rest-api] [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set ‘jakarta.persistence.jdbc.url’ for common cases or ‘hibernate.dialect’ when a custom Dialect implementation must be provided)
2024-06-07T07:06:16.788Z WARN 12355 — [springboot-blog-rest-api] [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set ‘jakarta.persistence.jdbc.url’ for common cases or ‘hibernate.dialect’ when a custom Dialect implementation must be provided)
2024-06-07T07:06:16.799Z INFO 12355 — [springboot-blog-rest-api] [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2024-06-07T07:06:16.839Z INFO 12355 — [springboot-blog-rest-api] [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with ‘debug’ enabled.
2024-06-07T07:06:16.874Z ERROR 12355 — [springboot-blog-rest-api] [ restartedMain] o.s.boot.SpringApplication : Application run failed

Blockquote

@kirupa is the one who can give solution, there is extension of mysql that give 3 limits to connect the database , try it , if you know this method

Hi @AB_Anu , I checked and tried in the IDX project and found that the provided extension (as shown in the image) will work only if we are using VS Code locally. However, we are not using it locally.

i found mysql80 / mariadb

script to connect the db in this link below

https://nixos.wiki/wiki/Mysql

and postgresql

https://nixos.wiki/wiki/PostgreSQL

i hope it will be useful