SETTING UP MYSQL / MARIADB

INSTALL

debian / ubuntu

grab the right repo

    dpkg -l | grep mariadb # empty
    dpkg -l | grep mysql # empty
ls -lF /etc/apt/trusted.gpg.d/mariadb_release_signing_key.asc # not yet
ls -lF /etc/apt/sources.d/mariadb.list # not yet

apt-get install apt-transport-https curl
curl -o /etc/apt/trusted.gpg.d/mariadb_release_signing_key.asc https://mariadb.org/mariadb_release_signing_key.asc
echo deb https://mirror.docker.ru/mariadb/repo/10.9/debian bullseye main > /etc/apt/sources.d/mariadb.list

apt update
apt install mariadb-server mariadb-client

systemctl list-units | grep maria
systemctl status mariadb.service # already enabled

slackware

slackpkg install mariadb lz4 lzo liburing
which mysql
ldd /usr/bin/mysql | grep found
mysql --version

mysql_install_db
ls -alF /var/lib/mysql/
chown -R mysql. /var/lib/mysql/

ls -lF /etc/rc.d/rc.mysqld
chmod +x /etc/rc.d/rc.mysqld
pgrep -a mysql
pgrep -a maria
/etc/rc.d/rc.mysqld start

DBPREP

make it production ready and check

mysql_secure_installation

no need to provide password if you’re root@localhost (not sure it’s the one or the other or both)

mysql -u root

otherwise

mysql -u root -p

TUNING

listen to localhost only

ubuntu – it’s already the default

grep -r bind-address /etc/mysql/

slackware

cp -i /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.dist
vi /etc/my.cnf.d/server.cnf

bind-address = 127.0.0.1

vi /etc/rc.d/rc.mysqld

#SKIP="--skip-networking"

tail -F /var/lib/mysql/xc.err &
/etc/rc.d/rc.mysqld restart
netstat -lnp | grep mariadb # returns two lines, tcp and unix

DATABASE CREATION

Create a db with UTF-8 charset & collate e.g. for moodle

–or– with UTF-8

    create database DB
        DEFAULT CHARACTER SET utf8
        DEFAULT COLLATE utf8_general_ci;
    grant all privileges on DB.* to DUDE identified by 'DUDE-PASSWORD';
    flush privileges;

–or– with the defaults e.g. for m/monit

OPERATIONS

ls -lF /var/lib/mysql/*.err
tail -F /var/lib/mysql/*.err

list databases

show databases;

delete a database

drop database DB;

MAINTENANCE

See Database Character Set and Collation on how to check that the charset is right. That’s a MySQL 5 doc but should also work with MariaDB. On a db,

USE db_name;
SELECT @@character_set_database, @@collation_database;

or alternatively without being on that db,

SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'db_name';

The defaults are not right (latin1 instead of utf8),

    SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

NOTES

reset SQL user password

e.g. for root

select user from mysql.user;
ALTER USER root@localhost IDENTIFIED BY 'NEW-PASSWORD';
FLUSH PRIVILEGES;

inject SQL

Inject whatever SQL code you want in it,

app=mariadbprod
    docker exec -ti $app mysql -udbnameuser -pUSERPASS_HERE dbname < schema.sql

and check,

docker exec -ti $app mysql -udbnameuser -pUSERPASS_HERE dbname
show tables;
...

rename tables in a batch

11:15 < TheRealBug[slack]> for table in `mysql -u root -s -N -e “use old_db;show tables from old_db;“`; do ``
11:15 < TheRealBug[slack]>     mysql -u root -ppassword -s -N -e “use old_db;rename table old_db.$table to new_db.$table;“;
11:15 < TheRealBug[slack]> done

Resources

install

How To Install MariaDB on Ubuntu 18.04 / Ubuntu 16.04 https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/install-mariadb-on-ubuntu-16-04.html

Install MariaDB On Slackware https://docs.slackware.com/howtos:databases:install_mariadb_on_slackware

How To Install MariaDB on Debian 10 https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-debian-10

skip-networking

mariadb networked slackware-64-current https://www.linuxquestions.org/questions/slackware-14/mariadb-networked-slackware-64-current-4175693569/

Configuring MariaDB for Remote Client Access https://mariadb.com/kb/en/configuring-mariadb-for-remote-client-access/

database

Create and delete a MySQL database https://gridscale.io/en/community/tutorials/mysql-datenbank-erstellen-loeschen/

reset password

How To Reset Your MySQL or MariaDB Root Password https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password

How to Reset the MySQL Root Password https://linuxize.com/post/how-to-reset-a-mysql-root-password/

B.3.3.2 How to Reset the Root Password https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun