cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

mysql create database but say is already exist .... #699

Closed Paul75 closed 10 months ago

Paul75 commented 10 months ago

Describe the bug Whan i create databases, it tell that it already created ..

To reproduce

services.mysql.initialDatabases = [
    {
      name = "douane_declaration_simplifiee";
    }
    {
      name = "douane_donnees_communes";
    }
    {
      name = "disjoints";
    }
    {
      name = "tfe";
    }
  ];

  services.mysql.ensureUsers = [
    {
      name = "douane_declaration_simplifiee";
      password = "douane_declaration_simplifiees";
      ensurePermissions = {
        "`douane_declaration_simplifiee`.*" = "ALL PRIVILEGES";
      };
    }
    {
      name = "douane_donnees_communes";
      password = "declaration_simplifiee";
      ensurePermissions = {
        "`douane_donnees_communes`.*" = "ALL PRIVILEGES";
      };
    }
    {
      name = "user_disjoints";
      password = "user_disjoints";
      ensurePermissions = { "disjoints.*" = "ALL PRIVILEGES"; };
    }
    {
      name = "tfe_user";
      password = "tfe_user";
      ensurePermissions = { "tfe.*" = "ALL PRIVILEGES"; };
    }
    {
      name = "tfe_adm";
      password = "tfe_adm";
      ensurePermissions = { "tfe.*" = "ALL PRIVILEGES"; };
    }
    {
      name = "migration";
      password = "migration";
      ensurePermissions = { "*.*" = "ALL PRIVILEGES"; };
    }
  ];

and the output :

10:34:39 system            | mysql.1 started (pid=12892)
10:34:39 system            | mysql-configure.1 started (pid=12893)
10:34:39 mysql.1           | 2023-07-05T08:34:39.110869Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
10:34:39 mysql.1           | 2023-07-05T08:34:39.112187Z 0 [System] [MY-013169] [Server] /nix/store/pnfm2bihml39mp7ml1nf7l2a6bxdsy6c-mysql-8.0.33/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 12898
10:34:39 mysql.1           | 2023-07-05T08:34:39.141479Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
10:34:39 mysql.1           | 2023-07-05T08:34:39.992101Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
10:34:42 mysql.1           | 2023-07-05T08:34:42.555890Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
10:34:47 mysql.1           | 2023-07-05T08:34:47.019940Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
10:34:47 mysql.1           | 2023-07-05T08:34:47.019958Z 0 [System] [MY-010116] [Server] /nix/store/pnfm2bihml39mp7ml1nf7l2a6bxdsy6c-mysql-8.0.33/bin/mysqld (mysqld 8.0.33) starting as process 12892
10:34:47 mysql.1           | 2023-07-05T08:34:47.031670Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
10:34:47 mysql.1           | 2023-07-05T08:34:47.188437Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
10:34:47 mysql.1           | 2023-07-05T08:34:47.291943Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/run/mysqld/mysqlx.sock' failed, can't create lock file /run/mysqld/mysqlx.sock.lock'
10:34:47 mysql.1           | 2023-07-05T08:34:47.482599Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
10:34:47 mysql.1           | 2023-07-05T08:34:47.482637Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
10:34:47 mysql.1           | 2023-07-05T08:34:47.522179Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
10:34:47 mysql.1           | 2023-07-05T08:34:47.522241Z 0 [System] [MY-010931] [Server] /nix/store/pnfm2bihml39mp7ml1nf7l2a6bxdsy6c-mysql-8.0.33/bin/mysqld: ready for connections. Version: '8.0.33'  socket: '/home/pkbp512/www/GROUPE_SOCLE_IMPORT_EXPORT/.devenv/state/mysql.sock'  port: 3306  Source distribution.
10:34:48 mysql-configure.1 | mysqld is alive
10:34:48 mysql-configure.1 | Database douane_declaration_simplifiee exists, skipping creation.
10:34:48 mysql-configure.1 | Database douane_donnees_communes exists, skipping creation.
10:34:48 mysql-configure.1 | Creating initial database: disjoints
10:34:48 mysql-configure.1 | Creating initial database: tfe
10:34:48 mysql-configure.1 | Adding user: douane_declaration_simplifiee
10:34:48 mysql-configure.1 | Adding user: douane_donnees_communes
10:34:48 mysql-configure.1 | Adding user: user_disjoints
10:34:48 mysql-configure.1 | Adding user: tfe_user
10:34:48 mysql-configure.1 | Adding user: tfe_adm
10:34:48 mysql-configure.1 | Adding user: migration

Version

Paste the output of $ devenv version here. 0.6.3

Thanks

thenonameguy commented 10 months ago

What is the output after running:

git clean -xf $DEVENV_STATE

and re-running devenv up?

Paul75 commented 10 months ago

not have git on the directory......

thenonameguy commented 10 months ago

Devenv requires git to function, could you double check? In any case, what is the expected outcome that you are not getting?

Paul75 commented 10 months ago

but i want have git but on the directory not have git directory .git

Paul75 commented 10 months ago

I do this :

git init .
git clean -xf $DEVENV_STATE
devenv up

and the same ....

thenonameguy commented 10 months ago

You should already have git initialized as part of devenv init process. What is the problem with getting Database douane_declaration_simplifiee exists, skipping creation.?

Paul75 commented 10 months ago

Hello,

the probleme that is not created.

Thanks

thenonameguy commented 10 months ago

This is how the MySQL module checks whether it exists:

mysqlshow -u root douane_declaration_simplifiee

What does this return for you, when devenv up is running?

Paul75 commented 10 months ago

See this :

~/www/GROUPE_SOCLE_IMPORT_EXPORT$ mysqlshow -u root douane_declaration_simplifiee
Wildcard: douane_declaration_simplifiee
+-----------+
| Databases |
+-----------+
+-----------+
pkbp512@781640ZX0426:~/www/GROUPE_SOCLE_IMPORT_EXPORT$ 
thenonameguy commented 10 months ago

After running it, what is echo $?

Paul75 commented 10 months ago

hello,

pkbp512@781640ZX0426:~/www/GROUPE_SOCLE_IMPORT_EXPORT$ echo $
$
pkbp512@781640ZX0426:~/www/GROUPE_SOCLE_IMPORT_EXPORT$ 

Thanks

stephank commented 10 months ago

This is unfortunate mysqlshow behavior, documented in usage:

If last argument contains a shell or SQL wildcard (*,?,% or _) then only what's matched by the wildcard is shown.

So the workaround is to not use an underscore.

Underscores are quite common, though. There doesn't appear to be an option to disable this or escape it. Maybe we could instead do something like:

mysql -sB information_schema <<< 'select count(*) from schemata where schema_nama = "${database.name}"'

That should print (not exit) with 0 or 1.