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 MySQL Database in Linux Environment

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how to install the MySQL database under the Linux environment. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

1. Overview

For mysql binary installation, the advantage is that it can be installed in any path with good flexibility, and multiple mysql can be installed on one server. The disadvantage is that it has been compiled, the performance is not as good as the source code compilation, and the compilation parameters can not be flexibly customized. If users do not want to install either the simplest but inflexible RPM package or the complex and time-consuming source package, a compiled binary package will be the best choice.

two。 Pre-preparation 2.1download mysql binary installation package

Mysql official website: https://dev.mysql.com/downloads/mysql/

Because I downloaded the mysql-8.0.23-linux-glibc2.12-x86_64.tar version, if there is the latest version, then download the latest version.

2.2 Import mysql binary installation package

Transfer the installation package to the linux system package directory through the Xftp tool:

3.mysql deployment

Extract the mysql installation package

-- change to the installation directory cd / app-- to extract the xz zip file tar-xvf / app/package/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

Modify the name of the mysql folder

-- change mysql-8.0.23-linux-glibc2.12-x86_64 to mysql folder name mv / app/mysql-8.0.23-linux-glibc2.12-x86_64 / app/mysql

Create a data directory

-- create a data directory under the mysql root directory to store data mkdir / app/mysql/data

Create mysql user groups and mysql users

-- create mysql user groups and mysql users groupadd mysqluseradd-g mysql mysql

Modify mysql directory permissions

-- modify mysql directory permissions chown-R mysql.mysql / app/mysql/

Initialize the database

-- change to the mysql installation directory cd / app/mysql-- initialization database bin/mysqld-- initialize-- user=mysql-- basedir=/app/mysql-- datadir=/app/mysql/data

Configure mysql

-- first change to the mysql.support-files directory cd / app/mysql/support-files-- create files in mysql/support-files my-default.cnftouch my-default.cnf-- copy configuration files to / etc/my.cnfcp-a. / my-default.cnf / etc/my.cnf-- edit my.cnfvim / etc/my.cnf

Enter the following configuration content for my.cnf:

[client] port=3306socket=/tmp/ mysql.sock[mysqld] port=3306user=mysqlsocket=/tmp/mysql.sockbasedir=/app/mysqldatadir=/app/mysql/data

Configure environment variables

-- Editing the profile file vim / etc/profile-- to configure the mysql environment variable PATH=/data/mysql/bin:/data/mysql/lib:$PATHexport PATH-- to make the mysql environment variable effective source / etc/profile-- to see whether the environment variable is valid or not echo $PATH

Start mysql

Cd / app/mysql/binsystemctl start mysqldorservice mysql start

You may encounter the following error when starting mysql:

Failed to start mysqld.service: Unit not found.

Or

Starting MySQL.Logging to'/ app/mysql/data/dengwu.err'.

... ERROR! The server quit without updating PID file (/ app/mysql/data/dengwu.pid).

The solution is as follows:

-- if you need to install mariadb-serveryum install-y mariadb-server-- and then start the mariadb service systemctl start mariadb.service--, you can add the mariadb service boot systemctl enable mariadb.service

Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl-xe" for details.

The solution is as follows:

Chown-R mysql.mysql / app/mysql/

Starting MySQL... ERROR! The server quit without updating PID file (/ app/mysql/data/dengwu.pid).

The solution is as follows:

-- View mysql process ps-ef | grep mysqld-- kills mysql process kill-9 mysql process ID

Then restart mysql:

4. Modify mysql password

Root users log in to mysql for the first time because we don't know the initial password. Normally, we will reset a new password as follows:

-- Edit my.cnfvim / etc/my.cnf

Enter the following command line:

Default_authentication_plugin=mysql_native_password

If you forget your password and add:

-- Skip password verification (remove it when password is set) skip-grant-tables

Then log in to mysql:

-- sign in to mysqlmysql-u root-p

Then enter the command to view the mysql user group:

-- View the mysql user table select user,host,authentication_string from mysql.user

Check that the root user does not have permission to open a remote connection. If not, execute the following command:

-- modify root users to connect to update mysql.user set host='%' where user='root' remotely

After the remote connection permission is enabled, change the root user password:

-- if host is localhost, the @ character is followed by localhost, otherwise it is%, depending on the host result-- modify the encryption rule alter user 'root'@'%' identified by' qwer1234' password expire never;-- update the user's password alter user 'root'@'%' identified with mysql_native_password by' qwer1234';-- refresh permission flush privileges;-- modify the root user password alter user 'root'@'%' identified by' qwer1234'

If the firewall is enabled, you need to add permission to allow mysql port access. The specific commands are as follows:

-- allow access to firewall-cmd-- permanent-- zone=public-- add-port=3306/tcp-- reload firewall-cmd-- reload-- to see if access permission firewall-cmd is enabled-- permanent-- zone=public-- query-port=3306/tcp

Then restart mysql:

-- restart mysqlservice mysql restart;5. Configure mysql Ali Cloud Security Group Policy

Log in to Aliyun-> Security Group rules-> access rules-> entry Direction-> manually add the following policies:

Connect successfully using Navicat:

These are all the contents of the article "how to install MySQL database in Linux environment". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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

Development

Wechat

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

12
Report