"How to install and configure MySql and MariaDB in LInux"

提示:mariadb和mysql的配置以及安装流程都一样,本文章中mariadb举个例子,下载mysql的同样的方法,放心

Download MariaDB database

The first step-check whether the system is properly connected to the Internet

ping www.baidu.com

image.png
We test whether it is normal to surf the Internet. If the picture is the same, it means that the Internet can be used normally

Step 2-Precautions before downloading MariaDB

If we download the database, use the yum command

Introduction to yum command: windows has its own application mall, then yum is the application mall linked to linux, we use the yum command to download the application

Disadvantages: The path of the downloaded application is the default, which is not easy to find

Advantages: we can download the desired application with one line of command

----We clear the previously installed files before downloading

Tip: This step can be omitted, depending on personal needs,

If you have downloaded other applications using yum before, it is not recommended to use

 yum clean all  清空已安装文件   如果下载失败之后执行的.

Step 3-Download MariaDB database

yum install mariadb-server 安装mariadb数据库

image.png
After executing the above command, the download starts, and we don’t touch anything during the download process. In the
end, it shows the same content as the picture and we press y to build it. The
image.png
final result is that the download is complete!

Step 4-Start the database and initialize

1.1 Some commands to start the database

1.启动命令 systemctl start mariadb
2.重启命令 systemctl restart mariadb
3.关闭命令 systemctl stop mariadb

After the database is downloaded, start the database systemctl start mariadb

1.2 Commands for database initialization

    mysql_secure_installation

After starting the database, what we need to initialize is to set the database password
. You cannot enter the database without a password.
image.png

After entering the command, the prompt in the picture appears, press ENTER directly to build the bank

image.png
Then ask us if we set a password, we just press y

After pressing y, a password prompt appears: we enter the password and click ENTER
again to ask us if we are sure of the password. We enter the password again and then click ENTER to execute

image.png
After entering the password, the above prompt is displayed. Let’s press y. Press y
4 times in total

1.3 Set the database configuration

1.3.1 Enter the database

Enter the password and account number to enter the database command as follows:
image.png

    mysql -u root -p

Then a prompt to enter the password appears. After entering the password, you successfully enter the database (the password is transparent).
image.png
Successfully enter the database. Show databases is to query multiple databases.

1.3.2 Enter mysql database

Enter the mysql database and use use mysql
image.png

1.3.3 Query the user table

show tables is that there are multiple tables in the current database.
image.png
We need to query the user table, select host, and user from user. If
image.png
we configure it, query host and user.

1.3.4 Modify the host in the table


image.png
The purpose of changing localhost is to modify the content of the database to facilitate the modification of the database address.

1.3.5 Refresh the database configuration

image.png

刷新数据库配置 命令:flush privileges

Configure Linux firewall policy

Why configure the firewall: Now the database is normally accessed, but we can no longer operate the database on Linux every time, and may be connected remotely. At this time, the firewall does not allow remote access to the database, so we need to configure the firewall

Check firewall status

    命令: firewall-cmd --state

image.png

Prompt: After the second command is launched from the database, the
firewall is running when the running is executed .
If not running, then no second step is required

Firewall configuration

Description: There is a configuration file in the firewall, which indicates how the firewall should operate when the Linux system is started!!!
Requirements: Tell the linux system that it does not need to start the firewall in the future

命令: `systemctl disable firewalld.service`

image.png

Turn off the firewall manually

Description: Manually turn off the firewall by command
Command:systemctl stop firewalld.service
image.png

So far we have successfully downloaded and configured the database.
We have configured the database link address and firewall restrictions.
Now our database is normally connected remotely.

Guess you like

Origin blog.csdn.net/weixin_45103228/article/details/113757287