You are not logged in.

#1 2024-08-18 18:49:00

JesseSteele
Member
From: Pacifica
Registered: 2022-07-08
Posts: 11
Website

Proper way to create MariaDB database in PKGBUILD .install script

I have a PKGBUILD file with install='structure.install'.

structure.install:

pre_install() {
  /usr/bin/mariadbd
  mariadb -e "
  CREATE DATABASE IF NOT EXISTS my_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  GRANT ALL PRIVILEGES ON my_db.* TO 'my_db_user'@'localhost' IDENTIFIED BY 'mydbpassword';
  FLUSH PRIVILEGES;"
}

pre_upgrade() {
  /usr/bin/mariadbd
  mariadb-dump my_db > /etc/myapp/my_db.sql
}

post_remove() {
  /usr/bin/mariadbd
  mariadb -e "
  DROP USER IF EXISTS 'my_db_user'@'localhost';
  DROP DATABASE IF EXISTS my_db;
  FLUSH PRIVILEGES;"
}

This never works.

I know this is run by chroot, so I start mariadb directly without systemctl.

What is the "right way" to create/export/drop a database in the package .install script? 1 or 2 or something else?...

1. Should I already have the .sql file and use an import command? What if the mariadb daemon isn't running? What about export and drop?
2. Is it better to simply copy the database into place directly in '/var/lib/mysql/'? What is the right command to do that? What about export and drop?

Offline

Board footer

Powered by FluxBB