December 2, 2021 13:58
Backup
ADD BACKUP USER TO DATABASE (localhost only) - pwd maybe with ‘openssl rand -base64 32’
sudo mysql -u rootcreate user 'databaseBackupUser'@'localhost' identified by '[PASSWORD]';grant SELECT, RELOAD, LOCK TABLES, REPLICATION CLIENT, SHOW VIEW, EVENT, TRIGGER on *.* to 'databaseBackupUser'@'localhost';quit;
BACKUP ALL DATABASES (no space at -p is intentionally)
mysqldump -u databaseBackupUser -p[PASSWORD] --all-databases --skip-lock-tables > /tmp/databaseExport.sql
RESTORE ALL DATABASES
sudo mysql -u root < /tmp/databaseExport.sql
Access
- Install
mariadb-serverormariadb-client - Install
phpmyadmin - [configure phpmyadmin]
Unlock root (works only on localhost) source
sudo mysql -u rootselect user,host,password,plugin from mysql.user;update mysql.user set plugin='' where user='root';flush privileges;select user,host,password,plugin from mysql.user;
Change root password:
SET PASSWORD FOR root@localhost=PASSWORD('password');
Create an other (root-)user (works only on localhost)
sudo mysql -u rootCREATE USER username;SET PASSWORD FOR username=PASSWORD('password');- (
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';OR (to allow permission modifications too)GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;) - (
SHOW GRANTS FOR 'username'@'%';) flush privileges;
PLEASE NOTE THIS TO ALLOW ACCESS FROM THE INTERNET
sudo grep -rnw '/etc/mysql' -e 'bind-address' | head -n 1;sudo nano ...- Comment ‘bind-address’ out OR ON OLDER MYSQL SERVERS:
sudo grep -rnw '/etc/mysql' -e 'skip-networking' | head -n 1;sudo nano ...- Comment ‘skip-networking’ out
You SHOULD CHANGE the character encoding by collation-server = utf8mb4_bin at file /etc/mysql/mariadb.conf.d/50-server.cnf
Note
What is debian-sys-maint used for?
By default it is used for telling the server to roll the logs. It needs at least the reload and shutdown privilege.
See the file /etc/logrotate.d/mysql-server
It is used by the /etc/init.d/mysql script to get the status of the server. It is used to gracefully shutdown/reload the server.
Here is the quote from the README.Debian
- MYSQL WON’T START OR STOP?
You may never ever delete the special mysql user “debian-sys-maint”. This user together with the credentials in /etc/mysql/debian.cnf are used by the init scripts to stop the server as they would require knowledge of the mysql root users password else.