Centos installation mariadb. Installing MariaDB on Windows


Today we are going to raise one of the most popular roles of any Linux server, which occupy a leading role in this functional segment. Setting up a CentOS 7 web server based on a bundle of a popular http server apache, interpreter php and database servers mysql, or briefly - installing lamp. This combination is the most popular configuration among web hosting today. Although lately the same company has been hot on its heels, but based on nginx, it may have already gotten ahead, I don’t have exact data on this matter.

This article is part of a single series of articles about the server.

Web server on CentOS 7

So, our centos web server will consist of three main components - http server apache, programming language interpreter php and database servers mysql. Let's get to know each of them a little:

  1. Apache- http server or simply Apache web server. It is cross-platform software that supports almost all popular operating systems, including Windows. It is valued primarily for its reliability and configuration flexibility, which can be significantly expanded thanks to plug-in modules, of which there are a great many. Among the disadvantages, they note a greater requirement for resources compared to other servers. Apache will not be able to support the same load as, for example, nginx with similar hardware parameters.
  2. PHP is a general-purpose programming language that is most often used in web development. Today it is the most popular language in this application area. Supported by almost all hosting providers.
  3. mysql— database management system. It has gained popularity among small and medium-sized applications, of which there are many on the web. So, like php, today it is the most popular database used on websites. Supported by most hosting providers. On CentOS it is installed instead of mysql mariadb- mysql fork. They are fully compatible; you can switch from one database to another and back at any time. Lately I have come across information that mariadb works faster than mysql and people are slowly moving to it. In practice, I did not have the opportunity to observe this, since I have never worked with loaded databases. But under normal conditions the difference is not noticeable.

The experimental server will be , the characteristics are as follows:

CPU2 cores
Memory8 Gb
Disk150 Gb SSD

This is a custom settings setting. They are not optimal in price, but these are exactly what I needed.

I would like to clarify right away that I am analyzing the basic default setting. To improve performance, increase reliability and ease of use, you need to install several more tools, which I will discuss separately. In general, what is in this article will be sufficient to organize a web server.

If you don't have a server yet, then you need to run . And if the server is already installed, then don’t forget it. I recommend paying attention to the settings, since there is a lot of useful information that I do not give in this article - updating the system, setting up a firewall, installing an editor, and much more.

Setting up apache on CentOS 7

On CentOS the apache service is called httpd. When I first became acquainted with this distribution, it was unusual for me. In Freebsd and Debian, with which I had previously worked, the web server service was called apache, although I noticed somewhere, it seems in the software, that the configuration file is called httpd.conf. To this day I don’t know why both of these names have spread. I would be glad if someone shared information about this with me in the comments.

Now let's get started installing apache. In CentOS 7 this is done very simply:

# yum install -y httpd

Add apache to startup:

# systemctl enable httpd

Launch apache on CentOS 7:

# systemctl start httpd

Check if the server has started:

# netstat -tulnp | grep httpd tcp6 0 0:::80:::* LISTEN 21586/httpd

Everything is fine, it hung on port 80, as expected. Now you can go to http://ip-address and see the picture:

Now let's set up apache. I prefer the following web hosting structure:

Let's create a structure like this:

# mkdir /web && mkdir /web/site1.ru && mkdir /web/site1.ru/www && mkdir /web/site1.ru/logs # chown -R apache. /web

IncludeOptionalconf.d/*.conf

If not, uncomment it and go to the /etc/httpd/conf.d directory. Let's create a file site1.ru.conf there:

ServerName site1.ru ServerAlias ​​www.site1.ru DocumentRoot /web/site1.ru/www Options FollowSymLinks AllowOverride All Require all granted ErrorLog /web/site1.ru/logs/error.log CustomLog /web/site1.ru/logs/access.log common

Restarting apache on centos

Now we restart apache:

# systemctl restart httpd

If any errors occur, look at the apache log /var/log/httpd/error_log. If everything is in order, then we will check whether our virtual host is configured normally. To do this, create in the folder /web/site1.ru/www file index.html the following content:

# mcedit /web/site1.ru/www/index.html

Apache is set!

# chown apache. /web/site1.ru/www/index.html

192.168.1.25 site1.ru

where 192.168.1.25 is the IP address of our web server.

Now in the browser we type the address http://site1.ru. If we see the picture:

it means everything is configured correctly. If there are any errors, then go look at the logs. Moreover, in this case, not the general httpd log, but the error log of a specific virtual host at /web/site1.ru/logs/error.log.

I’ll immediately draw your attention to setting up the rotation of virtual host logs. It often happens that if you don’t set it up right away, then you forget. But if the site has good traffic, then the logs will grow rapidly and can take up a lot of space. It is better to set up rotation of web server logs immediately after creation. It's not difficult to do this.

To configure virtual host log rotation, you need to edit the /etc/logrotate.d/httpd file. It is created during the installation of apache and includes setting the rotation of the default log location. And since we transferred the logs of each virtual host to an individual folder, we need to add these folders to this file:

# mcedit /etc/logrotate.d/httpd /web/*/logs/*.log/var/log/httpd/*log ( missingok notifempty sharedscripts delaycompress postrotate /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true endscript )

In principle, the simplest web server is already ready and can be used. But it is unlikely that now there will be sites with static content for which only html support is sufficient. So let's continue with our setup.

If you need to organize the operation of the site according to the protocol https, then use the manual for .

Installing php on CentOS 7

To support dynamic website content, let's take the next step. Let's install php on CentOS 7:

# yum install -y php

And then a few more useful components. Let's install popular modules for php:

# yum install -y php-mysql php-mbstring php-mcrypt php-devel php-xml php-gd

Let's restart apache:

# systemctl restart httpd

Let's create a file in the virtual host directory and check the operation of php:

# mcedit /web/site1.ru/www/index.php# chown apache. /web/site1.ru/www/index.php

Go to http://site1.ru/index.php

You should see php information output. If something is wrong, some errors have arisen, look at the virtual host error log, php errors will also be there.

Where is php.ini?

After installation, the question often arises: where are the php settings stored? Traditionally, they are located in a single settings file. On CentOS php.ini is in /etc, right at the root. There you can edit global settings for all virtual hosts. Personal settings for each site can be made separately in the virtual host configuration file that we made earlier. Let's add some useful settings there:

# mcedit /etc/httpd/conf.d/site1.ru.conf

Add at the very end, before

Php_admin_value date.timezone "Europe/Moscow" php_admin_value max_execution_time 60 php_admin_value upload_max_filesize 30M

To apply the settings you need to restart Apache. You can now see the settings change in the phpinfo output.

Upgrading to php 5.6 on CentOS 7

In our example we installed on CentOS 7 php 5.4 from the standard repository. What if we need a newer version, for example php 5.6? In this case, you need to update php.

# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm # rpm -Uvh remi-release-7*.rpm

Now update php 5.4 to php 5.6:

# yum --enablerepo=remi,remi-php56 install php php-common php-mysql php-mbstring php-mcrypt php-devel php-xml php-gd

Restart apache:

# systemctl restart httpd

And let's go look at the output of phpinfo - http://site1.ru/index.php

Great, we've updated php to version 5.6.

Installing MySQL on CentOS 7

As I wrote earlier, the mysql fork is now becoming increasingly widespread - mariadb. It is fully compatible with mysql, so you can use it with confidence. I prefer to use it.

Installing mariadb on CentOS 7:

# yum install -y mariadb mariadb-server

Add mariadb to autostart:

# systemctl enable mariadb.service

Launch mariadb:

# systemctl start mariadb

We check whether it has started or not:

# netstat -tulnp | grep mysqld tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22276/mysqld

Please note that it is even displayed in the system as a mysqld service. Now we run the standard security configuration script:

# /usr/bin/mysql_secure_installation

I will not give the entire output of this script, everything is quite simple and clear. First, we set a password for root (the current password after installation is empty), then we delete anonymous users, disable the ability to connect root remotely, and delete the test user and database.

File settings mysql/mariadb is in /etc/my.cnf. For normal work, the default settings are sufficient. But if you decide to change them, don't forget to restart the database service.

Restart mariadb/mysql on CentOS 7:

# systemctl restart mariadb

That's all. The basic functionality of the web server on CentOS 7 is configured.

I will be glad to receive comments on the topic of the article. Let me remind you that this article is part of a single series of articles about the server.

Kali Linux Workshop

The course is for those who are interested in conducting penetration tests and want to practically try themselves in situations close to real ones. The course is designed for those who do not yet have experience in information security. The training lasts 3 months, 4 hours per week. What this course will give you:
  • Search for and exploit vulnerabilities or configuration flaws in corporate networks, web sites, and servers. Emphasis on pentesting of Windows OS and security of the corporate segment.
  • Learning tools such as metasploit, sqlmap, wireshark, burp suite and many others.
  • Mastering the Kali Linux tools in practice - any information security specialist should be familiar with it.
Test yourself on the entrance test and see the program for more details. | |

1: Install MariaDB

Debian 9 contains the MariaDB 10.1 package in the standard repository. This is its default MySQL option.

To install it, update the package index:

Now install the package:

sudo apt install mariadb-server

The command will install MariaDB, but will not prompt you to choose a password or change other settings. Currently, the MariaDB installation has several vulnerabilities that need to be addressed.

2: Setting up MariaDB

After installation is complete, you need to run a security script that will remove untrusted parameters and protect the database from unauthorized access.

sudo mysql_secure_installation

The script will ask a series of questions. First you need to provide your MariaDB root password. This is a MariaDB administrative account that has elevated privileges. You just installed MariaDB and haven't made any configuration changes yet, you don't have this password yet, so just press Enter.

In the next request, the script will ask you to configure the root password for the database. Type N and press Enter. On Debian, the MariaDB root account is closely tied to automated system maintenance, so you cannot change the default authentication methods for this account. Otherwise, when updating the package, the database may be damaged, and access to the root account may be lost. Later we'll look at how to set up an additional administrator account if socket authentication doesn't work for you.

For other questions, you can press Y and Enter. This will remove anonymous users and test databases, disable remote root logins, and update the current MariaDB settings.

3: Configuring password authentication support

On new Debian installations, the MariaDB root user by default supports authentication using the unix_socket plugin rather than using a password. This can improve security and usability in many cases, but can also make things more difficult if you need to allow access to an external program (such as phpMyAdmin).

Since the server uses the root user for tasks such as log rotation and starting and stopping the server, it is best not to change the root account authentication. Changing the credentials in the /etc/mysql/debian.cnf file may work initially, but further package updates will overwrite these changes. Instead, the developers recommend creating a separate administrator account with password authentication.

So, create an account called admin with the same rights as root, but with support for password authentication. To do this, open a MariaDB command prompt in a terminal:

Now create a new user with root privileges and password authentication support. Specify your username and password in the command.

GRANT ALL ON *.* TO "admin"@"localhost" IDENTIFIED BY "password" WITH GRANT OPTION;

Reset privileges:

FLUSH PRIVILEGES;

Close the MariaDB shell:

4: Testing MariaDB

When installed from the standard repository, MariaDB starts automatically. To verify this, check the service status:

sudo systemctl status mariadb
mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-09-04 16:22:47 UTC; 2h 35min ago
Process: 15596 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSIT
Process: 15594 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Process: 15478 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||
Process: 15474 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITI
Process: 15471 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysql
Main PID: 15567 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 27 (limit: 4915)
CGroup: /system.slice/mariadb.service
└─15567 /usr/sbin/mysqld
Sep 04 16:22:45 deb-mysql1 systemd: Starting MariaDB database server...
Sep 04 16:22:46 deb-mysql1 mysqld: 2018-09-04 16:22:46 140183374869056 /usr/sbin/mysqld (mysqld 10.1.26-MariaDB-0+deb9u1) starting as process 15567 ...
Sep 04 16:22:47 deb-mysql1 systemd: Started MariaDB database server.

If the DBMS does not start for some reason, enter:

sudo systemctl start mariadb

To further check, you can try connecting to the database using the mysqladmin tool (this is a client that allows you to run administrative commands). For example, this command will connect to MariaDB as root and output the version using a Unix socket:

sudo mysqladmin version
mysqladmin Ver 9.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Server version 10.1.26-MariaDB-0+deb9u1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 2 hours 44 min 46 sec
Threads: 1 Questions: 36 Slow queries: 0 Opens: 21 Flush tables: 1 Open tables: 15 Queries per second avg: 0.003

If you have created an additional administrator, you can perform this operation using the command:

mysqladmin -u admin -p version

MariaDB is running and working properly.

What is MariaDB

MariaDB is a database management system (DBMS) that is based on MySQL and is largely compatible with it.

MariaDB and MySQL are fully compatible in SQL query syntax. That is, if your program uses MySQL databases (for example, a website in PHP), then when switching to MariaDB you do not need to change anything in the program.

MariaDB is also binary compatible with MySQL connectors. Those. If you use MySQL connectors, you don't need to change them when moving to MariaDB.

MariaDB is compatible with MySQL database formats, but there are some caveats. If you transfer databases via export/import (for example, using a .SQL file), then the databases transferred in this way will be fully compatible between any versions and do not require any further actions. However, if you installed MariaDB on top of MySQL, that is, MariaDB uses database files from MySQL, then you need to consider compatibility:

  • MariaDB 10.2 is compatible with previous versions of MariaDB data files, as well as MySQL 5.6 and MySQL 5.7, but is not compatible with MySQL 8.0.
  • MariaDB 10.1 is compatible with previous versions of MariaDB data files, as well as MySQL 5.6.

More information: https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/

MariaDB runs on Windows and Linux. This program is completely open source. It is distributed both in the form of source codes and compiled executable files for Windows and all popular Linux distributions.

Why MariaDB is better than MySQL

MariaDB supports more storage engines (Storage Engines).

In addition to the standard MyISAM, BLACKHOLE, CSV, MEMORY, ARCHIVE, and MERGE storage engines, MariaDB also provides the following:

  • ColumnStore, a column-oriented storage system, is optimized for data warehousing.
  • MyRocks, a highly compressed storage system, added in version 10.2
  • Aria, a replacement for MyISAM with improved caching.
  • FederatedX (replacement for Federated)
  • OQGRAPH.
  • SphinxSE.
  • TokuDB.
  • CONNECT.
  • SEQUENCE.
  • Spider.
  • Cassandra.

MariaDB has many different improvements and optimizations in processing speed.

MariaDB has been updated with new extensions and features.

Download MariaDB for Windows

MariaDB is free and it is highly recommended to download it from the official website. MariaDB download page: https://downloads.mariadb.org/

You will see several episodes - several major versions of the program. If you do not need any specific compatibility with MySQL, then simply select the latest version and click the “Download” button

Since this program works on different operating systems, in the next window you will see a large selection of files for downloading.

Files Windows x86_64- these are 64-bit versions, and Windows x86- 32-bit.

.zip- These are portable versions that need to be installed independently, but which give complete freedom in fine tuning. A .msi is an installer for Windows.

In this instruction I will show you an example of working with the version .zip.

On the next page, just click the button: “ No thanks, just take me to the download»:

Installing MariaDB on Windows

For Windows, the MariaDB DBMS is distributed as an installer and a ZIP archive. I prefer installing from a ZIP archive because it gives me complete control over the process.

In all examples I install in the folder C:\Server\bin\, since I have MariaDB as part of a web server installed with . If yours is different, then take this into account and make appropriate adjustments.

mariadb and move to C:\Server\bin\.

Move the folder C:\Server\bin\mariadb\data\ to a folder C:\Server\data\DB\.

In folder C:\Server\bin\mariadb\ create a file my.cnf and copy into it:

Switching from MySQL to MariaDB on Windows

Switching from MySQL to MariaDB while maintaining databases

You can make the transition in different ways. I will show you the most universal method that guarantees full compatibility and no further problems.

You need to start by creating a backup copy of your databases. We'll do this on the command line using a utility (comes with MySQL and is located in the folder bin).

Open Windows Command Prompt. To do this, click Win+x and select Windows PowerShell (Administrator). In the window that opens, do

Let's go to the folder where this utility is located (you may have a different path):

Cd C:\Server\bin\mysql-8.0\bin\

Make a dump (backup) of all databases with the following command:

Mysqldump.exe -u root -p --all-databases > all-databases.sql

Now in the folder C:\Server\bin\mysql-8.0\bin\ the file will appear all-databases.sql- be sure to copy it to a safe place!

Now stop the MySQL service and remove it from startup:

Additionally, copy the folder to a safe place C:\Server\data\DB\data\- this is an additional backup copy of the MySQL database files - in case something goes wrong with MariaDB and you want to return to MySQL.

Now delete the folders C:\Server\bin\mysql-8.0\(binary files) and C:\Server\data\DB\data\(Database).

Unpack the downloaded archive from MariaDB, rename the folder to mariadb and move to C:\Server\bin\.

Move the folder C:\Server\bin\mariadb\data\ to a folder C:\Server\data\DB\.

In folder C:\Server\bin\mariadb\ create a file my.cnf and copy into it:

Datadir="c:/Server/data/DB/data/"

To install and start the service, run the commands:

C:\Server\bin\mariadb\bin\mysqld --install net start mysql

To deploy databases from a backup, go to the folder C:\Server\bin\mariadb\bin\:

Cmd cd C:\Server\bin\mariadb\bin\

And run a command like:

Mysql -uroot< C:\путь\до\файла\резервной_копии.sql

For example, I have a file all-databases.sql with a backup copy of the databases is placed in the folder h:\Dropbox\!Backup\, then my command is like this:

Mysql -uroot< h:\Dropbox\!Backup\all-databases.sql

Wait until the import is completed - if the file is large, the process may take longer.

Switching from MySQL to MariaDB without saving databases

Stop the MySQL service and remove it from startup:

Net stop mysql c:\Server\bin\mysql-8.0\bin\mysqld --remove

Delete folders C:\Server\bin\mysql-8.0\(binary files) and C:\Server\data\DB\data\(Database).

Unpack the downloaded archive from MariaDB, rename the folder to mariadb and move to C:\Server\bin\.

Move the folder C:\Server\bin\mariadb\data\ to a folder C:\Server\data\DB\.

In folder C:\Server\bin\mariadb\ create a file my.cnf and copy into it:

Datadir="c:/Server/data/DB/data/"

To install and start the service, run the commands:

C:\Server\bin\mariadb\bin\mysqld --install net start mysql

Since Debian 9, the popular MySQL database management system has been replaced by MariaDB. This DBMS is a fork of MySQL created by its original developers, who were dissatisfied with Oracle's licensing policy and feared that MySQL might become a more closed product. MariaDB is fully compatible with MySQL, which means that the replacement will be as transparent as possible and all applications that worked with MySQL will also work with MariaDB. And we will look at some of the features of this transition.

First of all, let's say that all commands, instructions, scripts, etc. and so on. who previously worked with MySQL will also work with MariaDB; no changes need to be made, and many users simply may not notice that they are working with a different DBMS.

But there are also differences, primarily related to security and were introduced by the Debian team. One of the main differences is that MariaDB is included in Debian 9 does not ask for root password during installation. After which the user is left somewhat confused, what to do next? Adding fuel to the fire is the fact that most instructions on the Internet consider managing MySQL purely through the phpMyAdmin control panel, and users without command line skills find themselves in a particularly helpless state.

"How to set root password in MariaDB"in different variations is one of the popular search queries related to this DBMS. But let’s not be too harsh, but first let’s figure out what the Debian developers did and why.

The biggest security problem with MySQL is that database access credentials are stored in clear text in web application configuration files. Considering that many users do not bother and make the root superuser the owner of all databases, the problem becomes quite serious. And if you consider that a fairly wide range of people can have access to web application files, including not only employees, but also freelancers, things get really bad.

Therefore, in Debian, authentication via a UNIX socket is provided for the root superuser in MariaDB and is implemented in such a way that only the system superuser can get unrestricted access to MariaDB and only in command line mode. From a security point of view, this is very correct, since now third-party users and web applications will not be able to gain root access, even if they somehow learned the password.

All this is good, but what should an ordinary user do who has installed MariaDB on his server and wants to upload a site database dump to it? First of all, create a user, preferably more than one. To do this, raise your rights in the system to root via su or sudo and run the command:

Mysql -u root

This will take you to the MariaDB command line. To create a new user, run the command:

create user "andrey" @ "localhost" identified by "password" ;

In our example we created a user andrey with password password.

Now let's assign him rights. First of all, let’s explicitly take away the rights to other people’s databases:

grant usage on *.* to "andrey"@"localhost";

And we will issue full rights to databases with the name template andrey_basename, this approach will allow us to automatically grant rights to all new databases that the user will create.

grant all privileges on `andrey\_%`.* to "andrey"@"localhost";

Note that the pattern is wrapped in characters grave (`), which is located on the key with the Russian letter E.

All that remains is to reload the privileges and exit the MariaDB console

flush privileges;
quit;

After which you can return to the usual tools for working with MySQL/MariaDB, for example, phpMyAdmin:


Please note that this method, unlike the common recommendations “enable root in MariaDB,” allows you to maintain increased system security, which is important if third parties have access to it. We also do not recommend keeping all databases under one user, ideally one site (or other application) - one user, this will allow you to change the password without wasting time and effort in case of compromise or its potential (for example, you were hired to work with the site freelancer).

Installing MariaDB from the developer repositories

The Debian operating system has many advantages, one of them for which it is most loved is its stability. Set it and forget it - that’s exactly what it’s about, but the downside of this approach is conservatism; many packages do not have as recent versions as we would sometimes like. Currently, MariaDB 10.1 ships with Debian 9, while the current versions are 10.2 and 10.3.

Therefore, if you need some new MariaDB features or just want to use the latest stable versions of the software, you can install MariaDB directly from the developer's repositories. This is not difficult to do, but you should make a full backup of your server before taking any potentially dangerous action.

To do this, run the following command in the server console with superuser rights:

Mysqldump -u root --all-databases > ~/my_backup.sql

This command will save all MariaDB databases, including service ones, to a file my_backup.sql in the directory /root and, if something goes wrong, you can always restore the state of your server at the time the copy was created.

You can get installation instructions on a special page on the official website.

It is made very conveniently: you select your distribution, its release, DBMS version and mirror - after which you receive ready-made instructions for installation. To save you time, we will present it here (we will be installing MariaDB 10.3 on Debian 9):

Apt-get install software-properties-common dirmngr
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
add-apt-repository "deb http://mirror.mephi.ru/mariadb/repo/10.3/debian stretch main"

So that you understand what you are doing, let’s briefly comment on these commands. The first of them adds the necessary dependencies to the system, the second installs the key with which the packages are signed, and the third, finally, adds the repository itself to the system.

Now let's update the list of packages:

Apt-get update

and install the new version of MariaDB:

Apt-get install mariadb-server

Please note that the package manager will correctly remove the previous version and install the new one, while all databases will be saved and will continue to work with the new version of MariaDB.

Secondly, when installing MariaDB from the developers, the installer will ask you to set the root password, since authentication via a UNIX socket is not used in this version.

This may please some, but if you have managed to understand and appreciate all the advantages of the method from the Debain developers, then a reasonable question will arise: is it possible to return it to the way it was? Can. To do this, open the configuration file /etc/mysql/mariadb.conf.d/50-server.cnf and add to section line:

Plugin-load-add = auth_socket.so

Let's restart the DBMS:

Service mysqld restart

Let's try to log in from a regular user account:

Even though the system will ask us for a password and we will enter it correctly, we will still be denied access. Let's try again via phpMyAdmin:

And here we will not have success. Great! Now only the system superuser has access with DBMS superuser rights and we do not need to worry that the MariaDB root password will become known to anyone.

I decided to stop using MySQL, or rather, completely transfer all my servers to its fork - MariaDB. Taking this opportunity, I would like to talk about the process of installing MariaDB 10.1 on Debian 8. It should be noted that a brief description of installing MariaDB is on the official project page. I decided to devote a separate post to this issue, in which I want to describe the necessary actions after installing MariaDB on the server.

Before installing MariaDB, you need to add its repository. The MariaDB website recommends installing the software-properties-common package for this. I don't see any point in this and prefer to do everything manually.

Register the GPG key of the repository in the system:

Apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db

Add a description of the repository to the sources.list file. Open the file in the nano editor:

Nano /etc/apt/sources.list

Copy the following lines to the end:

Deb http://lon1.mirrors.digitalocean.com/mariadb/repo/10.1/debian jessie main deb-src http://lon1.mirrors.digitalocean.com/mariadb/repo/10.1/debian jessie main

We update the list of available packages:

Apt-get update

Let's start the MariaDB 10.1 installation process:

Apt-get install mariadb-server

During installation we will be asked to enter a password for the root user. This completes the process of installing MariaDB on Debian 8. Now let's move on to setting up the server.

To increase the reliability of our server, we need to meet minimum security requirements. Prohibit authorization under the root user from remote hosts. If there is a test database and an anonymous user, you need to remove them from the server. To make the task easier, use the script:

Mysql_secure_installation

Default data storage type

If you need to change the default data storage type, add the following lines to the my.cnf file:

Default-storage-engine = innodb

Make sure MariaDB uses InnoDB tables by default. To do this, run the command:

SHOW ENGINES;

Create a MariaDB user and database

To create a user in MariaDB use the command below:

CREATE USER "USER_NAME"@"localhost" IDENTIFIED BY "PASSWORD";

Create a new database:

CREATE DATABASE database_name;

We give full rights to the user USER_NAME on the databasename database:

GRANT ALL PRIVILEGES ON database_name.* TO "USER_NAME"@"localhost";

Now you need to update all privileges:

FLUSH PRIVILEGES

To view privileges, run the command:

SHOW GRANTS FOR "USER_NAME"@"localhost";

Binary logs

MariaDB writes all database changes to a binary log; it is necessary for the replication mechanism to work. If you did not make backups or they are outdated, binary logs can be used to restore data. However, there is no guarantee that the data will be fully or partially recovered. Success will depend on the size, storage time of binary logs, and frequency of backups.

To disable binary logs, comment out the lines in the my.cnf file:

#log_bin = /var/log/mysql/mariadb-bin #log_bin_index = /var/log/mysql/mariadb-bin.index







2024 gtavrl.ru.