Install MySql on Linux - Install, start and connect mysql through RPM management

RPM
RPM (Red-Hat Package Manager) rpm package manager is a tool used by Red Hat Linux for management and installation.
We can also use it to manage our Centos (equivalent to the "Programs and Functions" of our windows system management. "Management such as uninstalling or changing applications)

Install

1. Check whether the database is installed in mysqlthe mariadbsystem

#当前系统中安装的所有软件
rpm -qa
#当前系统中安装的名称中带有mysql的软件
rmp -qa | grep mysql
#当前系统中安装的名称中带有mariadb的软件
rmp -qa | grep mariadb

Note:
1. If the mysql database is already installed in the current system, the installation will fail.
2. The mariadb that comes with CentOS7 conflicts with the masql database and needs to be uninstalled.
3. -q is query, -a is all, | is the pipe character, and grep is the search character command.

Insert image description here

2. Uninstall the installed conflicting software

#Uninstall software command format

rpm -e --nodeps 软件名称
#卸载mariadb
rpm -e --nodeps 

3. Download

1. mysql download address Download Red Hat-RPM bundle in community services
Insert image description here

Note that you need to select the version here. The default is the latest version. Ours is Linux7 (I installed it wrong the first time and installed 8. As a result, the system is CentOS7, the package and system do not match, and various dependencies are missing) How many systems are installed?

Insert image description here2. Or directly download the link I provided:

wget  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar

Alternatively, MySQL 5.7 version is also suitable for this environment.

wget  https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar

4. Unzip and install

I unzipped it here into the /usr/local/mysql file.

tar -axvf mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar -C /usr/local/mysql/

After decompression, you will see many rpm package files

-rw-r--r--. 1 7155 31415  28991900 323 01:26 mysql-community-client-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    318868 323 01:26 mysql-community-common-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   4363096 323 01:26 mysql-community-devel-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  47993516 323 01:26 mysql-community-embedded-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  23315792 323 01:26 mysql-community-embedded-compat-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 132675656 323 01:26 mysql-community-embedded-devel-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2704332 323 01:26 mysql-community-libs-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   1264876 323 01:26 mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 186231736 323 01:27 mysql-community-server-5.7.38-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 126641600 323 01:27 mysql-community-test-5.7.38-1.el7.x86_64.rpm

We don’t need to install so many packages here, we only need to install 6 of them in sequence.

Use the command rpm -ivh {-file-name}to perform the installation operation.
Install the rpm package in order according to the dependencies. The dependencies are common→libs→devel→client→libs-compat→server.

1、 rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm
2、 rpm -ivh mysql-community-libs-5.7.38-1.el7.x86_64.rpm
3、 rpm -ivh mysql-community-devel-5.7.38-1.el7.x86_64.rpm
4、 rpm -ivh mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm
5、 rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm
6、 rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm

Note: In ivh, i-install installation; v-verbose progress bar; h-hash hash verification

When executing the last installation command, an error was
Insert image description here
reported, saying that we were missing a dependency on net-tools. Let’s install it yum install net-tools. After installation, the last one mysql-community-server-5.7.38-1.el7.x86_64.rpmwas successfully installed normally.

5. Start mqsql

#启动
systemctl start mysqld
#查看当前服务状态
systemctl status mysqld
#设置开机自启动
systemctl enable mysql

Because we have just installed the net-tools tool, all netstatcommands are now supported and you can view the startup service

#查看已启动的服务
netstat -tunlp
netstat -tunlp | grep mysql

Also check the mysql process

ps -ef | grep mysql

6. View temporary password

There will be a log file in the installation directory, which contains the password line information. Let’s search it.

cat /var/log/mysqld.lg  | grep password

7. Log in to mysql, change password, and open permissions

Log in

mysql -u root -p
#输入刚获取的临时密码,然后回车

Revise

# 设置登录密码长度
set global validate_password_length = 4;
# 设置密码安全等级,这里为了方便设置低
set global validate_password_policy=LOW;
# 设置密码
set password = password("root")

Enable access

grant all on *.* to 'root'@'%'identified by 'root';
flush privileges;

8. Set up firewall and remote connection to database

Remember to open port 3306 of mysql, otherwise the firewall will block access to the database.

Set up firewall

#开发3306端口
[root@localhost log] firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
#重启防火墙
[root@localhost log]# firewall-cmd --reload
success
#查看当前开发的所有端口
[root@localhost log]# firewall-cmd --zone=public --list-ports
8080/tcp 3306/tcp

Port 3306 is the default port number for mysql installation.
We can also netstat -tunlop | grep mysqlview the port through the command

Now you can connect to the database normally

Guess you like

Origin blog.csdn.net/mrhaoxiaojun/article/details/125137055