|MariaDB and MySQL Is to use SQL Open source database , And share the same initial code base .MariaDB yes MySQL substitute , You can use the same command （mysql） And MySQL and MariaDB Database interaction . therefore , This paper also applies to MariaDB and MySQL.|
Start in Linux The system uses open source SQL Database bar .
MariaDB and MySQL Is to use SQL Open source database , And share the same initial code base .MariaDB yes MySQL substitute , You can use the same command （mysql） And MySQL and MariaDB Database interaction . therefore , This paper also applies to MariaDB and MySQL.
You can use your Linux Package manager installation for distribution MariaDB. On most distributions ,MariaDB It is divided into server package and client package . The server package provides the database “ engine ”, namely MariaDB Running in the background （ Usually on a physical server ） Part of , It listens for data input or data output requests . The client package provides mysql command , You can use it to communicate with the server .
stay RHEL、Fedora、CentOS Or a similar distribution ：
$ sudo dnf install mariadb mariadb-server
stay Debian、Ubuntu、Elementary Or a similar distribution ：
$ sudo apt install mariadb-client mariadb-server
Other operating systems may be packaged in different packaging systems MariaDB, So you may need to search your repository to find out how the maintainer of your distribution provides it .
because MariaDB Designed as part of the database server , It can run on a computer , And manage it from another computer . As long as you have access to the computer running it , You can use it mysql Command to manage the database . At the time of writing this article , I ran it on my local computer MariaDB, But you can also host on remote systems MariaDB Database interaction .
Start up MariaDB Before , You have to create an initial database . When initializing its file structure , You should define what you want MariaDB Users used . By default ,MariaDB Use current user , But you may want it to use a dedicated user account . Your package manager may have configured a system user and group for you . Use grep Find out if there is one mysql Group ：
grep mysql /etc/group mysql:x:27:
You can also be in /etc/passwd Looking for this dedicated user , But usually , If there are groups, there will be users . If there is no special mysql Users and groups , Can be in /etc/group Looking for an obvious alternative （ such as mariadb）. without , Please read your distribution documentation to learn about MariaDB How it works .
Suppose your installation uses mysql, Initialize the database environment ：
$ sudo mysql_install_db --user=mysql Installing MariaDB/MySQL system tables in '/var/lib/mysql'... OK [...]
The result of this step shows the configuration you have to perform next MariaDB The task of ：
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: '/usr/bin/mysqladmin' -u root password 'new-password' '/usr/bin/mysqladmin' -u root -h $(hostname) password 'new-password' Alternatively you can run: '/usr/bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.
Use your distribution's initialization system to start MariaDB：
sudo systemctl start mariadb
Enable... At startup MariaDB The server ：
sudo systemctl enable --now mariadb
Now you have one MariaDB The server , Set a password for it ：
mysqladmin -u root password 'myreallysecurepassphrase' mysqladmin -u root -h $(hostname) password 'myreallysecurepassphrase'
Last , If you're going to use it on a production server , Please run before you go online mysql_secure_installation command .
This paper addresses ：https://www.linuxprobe.com/mariadb-mysql-linux.html