Running
After MariaDB is installed, you can configure database files, start the database, manage users, and stop the database to check whether the database is running properly.
The installation directories for both installation methods (source code compilation and RPM package installation) are the same. The default directory is /usr/local/mariadb.
- Modify the configuration file.
- Modify the my.cnf file and change the file paths (including the software installation path basedir and data path datadir) based on actual requirements.
1 2
rm -f /etc/my.cnf echo -e "[mysqld_safe]\nlog-error=/data/mariadb/log/mysql.log\npid-file=/data/mariadb/run/mysqld.pid\n[mysqldump]\nquick\n[mysql]\nno-auto-rehash\n[mysqld]\nbasedir=/usr/local/mariadb\ntmpdir=/data/mariadb/tmp\ndatadir=/data/mariadb/data\nsocket=/data/mariadb/run/mysql.sock\ncharacter-set-server=utf8\ndefault_authentication_plugin=mysql_native_password\nport=3306\nuser=mysql\n" > /etc/my.cnf
- Check that the my.cnf file is correctly modified.
1cat /etc/my.cnf
If user mysql (OS user) is configured in the my.cnf file, the corresponding mysql user (database user) will be created when the database is initialized.
- Change the group and user of the /etc/my.cnf file to mysql:mysql.
1chown mysql:mysql /etc/my.cnf
- Modify the my.cnf file and change the file paths (including the software installation path basedir and data path datadir) based on actual requirements.
- Set the environment variables.
- After the compilation and installation are complete, add the path of the MariaDB binary file to the PATH environment variable.
In the following command, /usr/local/mariadb/bin is the absolute path of the binary file in the installation directory. Replace it with the actual one.
1echo export PATH=$PATH:/usr/local/mariadb/bin >> /etc/profile
- Make the environment variable settings take effect.
1source /etc/profile
- After the compilation and installation are complete, add the path of the MariaDB binary file to the PATH environment variable.
- Initialize the database.
1/usr/local/mariadb/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb/data

If the paths are changed during the installation, change the paths according to the actual situation.
If the initialization fails and the message "--initialize specified but the data directory has files in it." is displayed, run the following command to delete the data and initialize the database again.
1 2 3
ls /data/mariadb/data cd /data/mariadb/data/ rm -rf *
- Start the database.
The mysqld_safe script monitors the running status of the MariaDB service after the MariaDB service is started, and restarts the service when it breaks down. You can also run the following command to directly start the MariaDB service:
/usr/local/mariadb/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb/data &
- Run the following command to start the MariaDB service and press Enter:
1/usr/local/mariadb/bin/mysqld_safe --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb/data &

- Check whether the process has been started.
1ps -ef | grep mysql

- Run the following command to start the MariaDB service and press Enter:
- Switch to user mysql.
1 2
su - mysql whoami
- Log in to the database. Password is not required for the first login.
1/usr/local/mariadb/bin/mysql -uroot -S /data/mariadb/run/mysql.sock

Check the database users.
1 2 3
use mysql; show tables; select user,host from user;

- Configure the database user name and password.
- After logging in to the database, change the password of the root user for logging in to the database.
1alter user 'root'@'localhost' identified by "123456";
- Create a root user for all the other hosts in the domain.
1create user 'root'@'%' identified by '123456';
- Grant permissions.
1 2
grant all privileges on *.* to 'root'@'%'; flush privileges;
- Exit from the database.
1exit
- After logging in to the database, change the password of the root user for logging in to the database.
- Log in to the database using a password.
1/usr/local/mariadb/bin/mysql -uroot -p123456 -S /data/mariadb/run/mysql.sock

- Exit the database.
\q
or
exit
- Optional: Stop the database.
1/usr/local/mariadb/bin/mysqladmin -uroot -p123456 shutdown -S /data/mariadb/run/mysql.sock