Jan 03

RHCE: MariaDB Administration on Redhat/Fedora/CentOS

RHCE: MariaDB Administration on Redhat/Fedora/CentOS

 

Check if mariaDB is installed or not

130 yum list installed | grep ^mariadb

mariaDB originated from MySQL - after MySQL Got Bought by Oracle

133 yum list installed | grep ^mariadb

I see - installed though not completely

Output:

mariadb-libs.x86_64 1:5.5.52-1.el7 @anaconda

There are two other components: mariaDB - client component. MariaDB-server: Server Component

The MariaDB packages:
138 mariadb-bench.x86_64 mariadb-devel.x86_64 mariadb-server.x86_64 mariadb-test.x86_64 mariadb.x86_64

 

Install all packages at once

139 yum install mariadb*
140 yum list installed | grep ^mariadb

Now, I see the following, after I have installed - all MariaDB packages available in my system
mariadb.x86_64 1:5.5.52-1.el7 @local
mariadb-bench.x86_64 1:5.5.52-1.el7 @local
mariadb-devel.x86_64 1:5.5.52-1.el7 @local
mariadb-libs.x86_64 1:5.5.52-1.el7 @anaconda
mariadb-server.x86_64 1:5.5.52-1.el7 @local
mariadb-test.x86_64 1:5.5.52-1.el7 @local

MariaDB Configuration Files
149 ls /etc/my.cnf
150 ls /etc/my.cnf.d/*

The files
/etc/my.cnf.d/client.cnf /etc/my.cnf.d/mysql-clients.cnf /etc/my.cnf.d/server.cnf

153 vim /etc/my.cnf
154 vim /etc/my.cnf.d/client.cnf
155 vim /etc/my.cnf.d/server.cnf
156 vim /etc/my.cnf.d/mysql-clients.cnf
157 main config file /etc/my.cnf

158 grep -v ^# /etc/my.cnf : will show lines that are not comments
159 grep -v ^# /etc/my.cnf

The content of my.cnf : some lines are self explanatory

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

MariaDB messages are logged at: /var/log/mariadb/mariadb.log

 

MySQL Specific Selinux Contexts
171 ps -eZ | grep mysqld
I do not see anything as mysqld/maridb is not running

178 systemctl start mariadb.service
179 systemctl enable mariadb.service
180 ps -eZ | grep mysqld

now the output:
system_u:system_r:mysqld_safe_t:s0 4428 ? 00:00:00 mysqld_safe
system_u:system_r:mysqld_t:s0 4585 ? 00:00:00 mysqld

184 mysqld runs on it's own domain mysqld_t

Related Selinux file type: mysql_exec_t
etc_t is for /etc/my.cnf.d
mysql_db_t is for /var/lib/mysql/
mysql_log_t is for /var/log/mariadb/
189 ll -dZ /usr/libexec/mysqld /etc/my.cnf.d /var/lib/mysql /var/log/mariadb

The output - please note the Selinux Contexts in the output
drwxr-xr-x. root root system_u:object_r:mysqld_etc_t:s0 /etc/my.cnf.d
-rwxr-xr-x. root root system_u:object_r:mysqld_exec_t:s0 /usr/libexec/mysqld
drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 /var/lib/mysql
drwxr-x---. mysql mysql system_u:object_r:mysqld_log_t:s0 /var/log/mariadb

Corresponding Selinux Port Type: mysql_port_t
196 semanage port -l | grep mysqld
output:
mysqld_port_t tcp 1186, 3306, 63132-63164

Related Selinux Booleans: mysql_connect_any, selinuxuser_mysql_connect_enabled
200 getsebool -a | grep mysql

I see the output
mysql_connect_any --> off
selinuxuser_mysql_connect_enabled --> off

To install MariaDB-Server:
205 yum -y install mariadb-server
already installed. we installed with yum -y install mariadb* [installed everything together]

207 systemctl enable mariadb

We can run mysql_secure_installation - to secure our MariaDB installation
209 mysql_secure_installation

-----

The Output:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB


installation should now be secure.
Thanks for using MariaDB!

Enable MariaDB through Firewall and Allow traffic on Port 3306 - default mysql port
218 firewall-cmd --add-service=mysql --perm
220 firewall-cmd --reload

221 systemctl start mariadb
222 systemctl status mariadb
223 start mysql/mariadb

Run MySQL

224 mysql -u root -p

mysqldump is used to backup a database
mysql command can be used to restore a database
you can even use IDEs such as MySQL Workbench to backup and restore MySQL Databases

228 mysql -u root -p
229 mysqldump -u root -p testsayed > testsayeddb.sql

to restore - you need to use < testsayeddb.sql
231 mysql -u root -p testsayed < testsayeddb.sql

Backup and Restore MySQL Database

You can backup multiple databases at once, you can even backup some tables or other database objects using mysqldump

similarly, you can restore multiple databases at the same time using mysql command
just use multiple datbase or database object names with NO comma - one after another

235 mysqldump -u root -p DB1 DB2 DB3 > alldb.sql

when you use restore and give the sql file - if you use db name or table name before < then only that part will be restored irrespective hiow much data is there on the file

example
238 mysql -u root -p DB1 tbl1 < alldb.sql ;

you can use --all-databases or --databases with mysqldump command

Skip to toolbar