Mysql

MariaDB Installation on CentsOS7

Setup a Maria DB Server on CentOS7:

yum -y install mariadb-server mariadb
systemctl enable mariadb
systemctl status mariadb
mysql
Create MariaDB Server admin password:

mysqladmin -u root password 

Config external access from remote host/Tool to database Server:

cd /etc/my.cnf.d
vi server.cnf

Set to [mysqld] block:

[mysqld]
bind-address    = 0.0.0.0

Create User with external access rights:

mysql -u root -p 
create user ‘root’@’%’ IDENTIFIED BY ‘’;
grant all on test to ‘root’@’%’;
flush privileges;
Grant all privileges to database server admin user from extern!!

Be careful!
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ with grant option;
flush privileges;

MySQL Create new MySQL user by shell

Set a new user with access from a remote host:

CREATE USER 'DummyUser1'@'localhost' IDENTIFIED BY 'PASSWORD';
CREATE USER 'DummyUser2'@'%' IDENTIFIED BY 'PASSWORD';

Grant access to the users on both databses (DummyDB1- DummyDB2):

CREATE USER 'DummyUser1'@'localhost' IDENTIFIED BY 'PASSWORD';
CREATE USER 'DummyUser2'@'%' IDENTIFIED BY 'PASSWORD';</pre>

To give a user rights on a root privileged command:

vi /etc/sudoers
<USER> ALL = NOPASSWD: /bin/systemctl restart httpd

Now the user could restart the httpd deamon:

MariaDB backup script

WORKDIR=/home/bak
DB=<Datenbankname>
USER=<Username>
PW=<Passwort>
HOST=<Hostname>
DUMPFILE=$DB.sql
DUMPCOPY=$DB-$(date +%Y-%m-%d-%H-%M-%S).sql
/usr/local/bin/mysqldump
$DB -u $USER -h $HOST --password=$PW > $WORKDIR/$DUMPFILE
cp $WORKDIR/$DUMPFILE $WORKDIR/$DUMPCOPY

Delete backup files older than 3 days:

find $WORKDIR/*.sql -mtime +3 -exec rm -r {} \;