Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and configure MariaDB database in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to install and configure MariaDB database in Linux. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

Preparation:

First, configure IP, DNS and gateway to ensure that you can connect to the server using the remote connection tool, and the server yum command can be used normally.

Configure the firewall and open port 3306

Vi / etc/sysconfig/iptables # editing

-A RH-Firewall-1-INPUT-m state-- state NEW-m tcp-p tcp-- dport 3306-j ACCEPT # allow port 3306 to pass through the firewall

Special note: many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start, and the correct one should be added to the default port 22 rule.

After being added, the firewall rules are as follows:

*

# Firewall configuration written by system-config-securitylevel

# Manual customization of this file is not recommended.

* filter

: INPUT ACCEPT [0:0]

: FORWARD ACCEPT [0:0]

: OUTPUT ACCEPT [0:0]

: RH-Firewall-1-INPUT-[0:0]

-An INPUT-j RH-Firewall-1-INPUT

-A FORWARD-j RH-Firewall-1-INPUT

-A RH-Firewall-1-INPUT-I lo-j ACCEPT

-A RH-Firewall-1-INPUT-p icmp--icmp-type any-j ACCEPT

-A RH-Firewall-1-INPUT-p 50-j ACCEPT

-A RH-Firewall-1-INPUT-p 51-j ACCEPT

-A RH-Firewall-1-INPUT-p udp-- dport 5353-d 224.0.0.251-j ACCEPT

-A RH-Firewall-1-INPUT-p udp-m udp-- dport 631-j ACCEPT

-A RH-Firewall-1-INPUT-p tcp-m tcp-- dport 631-j ACCEPT

-A RH-Firewall-1-INPUT-m state-- state ESTABLISHED,RELATED-j ACCEPT

-A RH-Firewall-1-INPUT-m state-- state NEW-m tcp-p tcp-- dport 22-j ACCEPT

-A RH-Firewall-1-INPUT-m state-- state NEW-m tcp-p tcp-- dport 3306-j ACCEPT

-A RH-Firewall-1-INPUT-j REJECT-- reject-with icmp-host-prohibited

COMMIT

*

/ etc/init.d/iptables restart # finally restart the firewall for the configuration to take effect

3. Close SELINUX

Vi / etc/selinux/config

# SELINUX=enforcing # comment out

# SELINUXTYPE=targeted # comment out

SELINUX=disabled # increased

: wq! # Save exit

Shutdown-r now # restart the system

IV. System agreement

MariaDB installation package location: / usr/local/src

MariaDB compilation installation location: / usr/local/mysql

Download the software package

1. Download MariaDB

Http://mirrors.scie.in/mariadb/mariadb-5.5.33a/kvm-tarbake-jaunty-x86/mariadb-5.5.33a.tar.gz

2. Download cmake (MariaDB compilation tool)

Http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz

Download the above two software and upload them to the / usr/local/src directory

6. Install compilation tools and library files (use CentOS yum command to install, install more, facilitate later compilation and installation of php, nginx, etc.)

Yum install make apr* autoconf automake curl curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison

Installation section

First, install cmake

Cd / usr/local/src

Tar zxvf cmake-2.8.12.1.tar.gz

Cd cmake-2.8.12.1

. / configure

Make # compilation

Make install # installation

Second, install MariaDB

Groupadd mysql # add MariaDB database installation user group mysql

Useradd-g mysql mysql-s / bin/false # create a user mysql and join the mysql group, and do not allow mysql users to log in directly to the system

Mkdir-p / data/mysql # create MariaDB database storage directory

Chown-R mysql:mysql / data/mysql # set MariaDB database directory permissions

Mkdir-p / usr/local/mysql # create the MariaDB installation directory

Cd / usr/local/src

Tar zxvf mariadb-5.5.33a.tar.gz # decompression

Cd mariadb-5.5.33a # enter the installation directory

Cmake. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/data/mysql-DSYSCONFDIR=/etc

# configuration

Make # compilation

Make install # installation

Cd / usr/local/mysql

Cp. / support-files/my-huge.cnf / etc/my.cnf # copy the configuration file (Note: if there is a my.cnf by default under the / etc directory, you can overwrite it directly)

Vi / etc/my.cnf # edit the configuration file and add it in the [mysqld] section

Datadir = / data/mysql # add MariaDB database path

. / scripts/mysql_install_db-- user=mysql # generates MariaDB system database

Cp. / support-files/mysql.server / etc/rc.d/init.d/mysqld # add MariaDB to the system startup

Chmod 755 / etc/init.d/mysqld # increased execution permissions

Chkconfig mysqld on # join Boot Boot

Vi / etc/rc.d/init.d/mysqld # editing

Basedir = / usr/local/mysql # MariaDB program installation path

Datadir = / data/mysql # MariaDB database storage directory

Service mysqld start # Startup

Vi / etc/profile # adds the MariaDB service to the system environment variable: add the following line at the end

Export PATH=$PATH:/usr/local/mysql/bin

The following two lines link the library files of MariaDB to the default location of the system, so that you don't have to specify the library file address of MariaDB when compiling software like PHP.

Ln-s / usr/local/mysql/lib/mysql / usr/lib/mysql

Ln-s / usr/local/mysql/include/mysql / usr/include/mysql

Shutdown-r now # needs to restart the system and continue to operate under the terminal command line after waiting for the system to restart

Mysql_secure_installation # set the MariaDB database root account password

Press enter Y to enter the password twice according to the prompt

Or change the password directly / usr/local/mysql/bin/mysqladmin-u root-p password "123456" # change the password

Service mysqld restart # restart

Mysql-u root-p # enter the root password set above to log in to the mariadb console, as shown in the following figure:

This is how to install and configure the MariaDB database in the Linux shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report