--- title: 02 Mariadb description: published: true date: 2023-07-14T17:31:21.541Z tags: editor: markdown dateCreated: 2023-05-03T01:58:45.617Z --- # MariaDB MariaDB is a drop in replacement for MySQL, which is a database used by many services. First we create some folders mkdir -p ~/docker/mariadb First we will create a docker compose file vim ~/docker/mariadb/docker-compose.yml Add in the following text ``` version: '3' services: mariadb: image: mariadb:latest container_name: mariadb restart: always command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --skip-innodb-read-only-compressed volumes: - /data/mariadb/data:/var/lib/mysql - /data/mariadb/config:/etc/mysql/conf.d - /data/mariadb/logs:/var/log/mysql - /etc/localtime:/etc/localtime:ro environment: - MYSQL_ROOT_PASSWORD=SETAMYSQLROOTPASSWORDHERE ``` Be sure to set your mysql root password Mariadb should be good now, lets start the container sudo docker-compose -f ~/docker/mariadb/docker-compose.yml up -d Now we only need to initialize the database sudo docker exec -it mariadb mariadb-secure-installation Answer the first 3 questions with No and the rest with Yes You can get into the database with the following command (only if mariadb is running) sudo docker exec -it maridb mysql -p Enter the Mysql root password you provided during the creation of the mariadb container and you should be in. Here you can create databases with the following command create database DATABASENAME; Create a user with create user USERNAME@'LOCALIP' identified by 'USERPASSWORD'; Give privileges to a user on a database with grant all privileges on DATABASENAME.* to USERNAME@'LOCALIP'; And Flush the privileges with flush privileges; You can exit the mysql prompt with `exit;` and then pressing enter. # PHPMyAdmin Is a database manager for Mysql/MariaDB, it can be handy to manage the database with a GUI, Only install it if you need it, It is not needed for MariaDB to function at all. First we start with a project folder mkdir -p ~/docker/phpmyadmin Now we create a docker-compose file vim ~/docker/phpmyadmin/docker-compose.yml Paste in the following text ``` version: '3' networks: phpmyadmin: external: true name: phpmyadmin services: phpmyadmin: image: phpmyadmin container_name: phpmyadmin restart: always volumes: - /data/phpmyadmin/config.inc.php:/var/www/html/config.inc.php:ro networks: phpmyadmin: ipv4_address: 172.20.72.10 environment: - PMA_ARBITRARY=1 ``` Now we are going to create the phpmyadmin config folder. sudo mkdir /data/phpmyadmin Next we are going to create a config file sudo vim /data/phpmyadmin/config.inc.php Paste in the following text ```