Binary installation of mysql 5.7.23 under CentOS7

Binary installation of mysql 5.7.23 under CentOS7

The installation information on the Internet is uneven and full of pitfalls. It took me a lot of effort to install it. Then I sorted it out myself and recorded the installation process. At the same time, I also shared it with friends in need. Without further ado, let's get straight to the point.

1. First, go to the MySQL official website to download MySQL 5.7.23

Download

Official installation documentation

2. Upload files

Use the xftp tool to upload mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz to the server, and then use the command to check whether there is a default database.

rpm -qa | grep mysql

If so, uninstall it using the following command

rpm -e full name of existing MySQL

3. Add user groups and use them to manage MySQL to improve security

Create a mysql folder in the /usr/local directory, add user groups and users, and switch the group and user to which the mysql folder belongs to to the newly added user group and user

 [root@localhost local]# mkdir mysql
 [root@localhost local]# groupadd mysql
 [root@localhost local]# useradd -r -g mysql -s /bin/false mysql
 [root@localhost local]# [root@localhost local]# chown -R mysql:mysql mysql
 # chown -R "permission" or "name": "group" folder name

The step of adding a user group is not necessary and can be skipped. Then unzip the uploaded mysql compressed file and move it to the /usr/local/mysql folder.

tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local
 mv mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql

Configure the mysql service, copy mysql.server under support-files to /etc/init.d/ and give it a name

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

Then modify the parameters of /etc/init.d/mysql,

vi /etc/init.d/mysql

Revise

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

Next, configure the mysql configuration file. In other versions of mysql, there is a default configuration file under support-files, but this version does not have one. You need to prepare it yourself. Here is a simple basic configuration. Create a new my.cnf under /etc/. Some may prompt that it already exists, because the default database configuration file is also there, just overwrite it directly

touch my.cnf

The content of my.cnf is as follows

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during installation, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8

[mysqld]
# General configuration options basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character-set-server=utf8
default_storage_engine = InnoDB


sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Then switch to the mysql bin directory and execute the following command to initialize the database

[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

After the execution is completed, a default password will be automatically generated in the execution record. Be sure to copy it.

Start the mysql service through the command, and the following message will be displayed: Successful startup

service mysql start

4. Login

[root@localhost bin]# ./mysql -uroot -p
Enter password: Enter the default temporary password

After successful login, change the password

mysql> set password=password('new password');

To facilitate the use of Mysql commands, configure the mysql environment variables

[root@localhost bin]# vi /etc/profile

Make environment variables effective

[root@localhost bin]# source /etc/profile

From now on, you don't need to log in to mysql in the bin that switches to mysql.

5. Enable remote login

If the firewall is turned on, we need to open the port first before we can log in remotely. Use the following command to open the specified port and then restart the firewall.

[root@localhost local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost local]# firewall-cmd --reload

Set up remote login for mysql

mysql> grant all privileges on *.* to root@'%' identified by 'your password';
mysql> flush privileges;

6. Set the system to start automatically

This step is not necessary and does not affect the use, but CentOS is generally used as a server, so the MySQL server should start automatically at random. First check the list of automatically started services.

[root@localhost local]# chkconfig --list

Then add the mysql service and set it to start automatically

[root@localhost local]# chkconfig --add mysql
[root@localhost local]# chkconfig mysql on

Then use the above command to check the list of automatically started services again. You will see that mysql 2-5 are all displayed as on (some are displayed as on), indicating that the mysql service will start automatically when the machine starts.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Tutorial on installing mysql5.7.23 on Ubuntu 18.04
  • Ubuntu 18.04 installs mysql 5.7.23
  • The latest MySQL 5.7.23 installation and configuration graphic tutorial
  • MySQL 5.7.23 version installation tutorial and configuration method
  • MySQL 5.7.23 decompression version installation tutorial with pictures and text
  • Pitfalls and solutions for upgrading MySQL 5.7.23 in CentOS 7
  • MySQL 5.7.23 winx64 installation and configuration method graphic tutorial under win10
  • MySQL 5.7.23 installation and configuration graphic tutorial
  • mysql 5.7.23 winx64 decompression version installation tutorial
  • MySQL 5.7.23 installation and configuration method graphic tutorial

<<:  How to install Jenkins on CentOS 8

>>:  How to count down the date using bash

Recommend

The best way to start a jar package project under Centos7 server

Preface Everyone knows how to run a jar package o...

How to install docker on Linux system and log in to docker container through ssh

Note: I use Centos to install docker Step 1: Inst...

el-table in vue realizes automatic ceiling effect (supports fixed)

Table of contents Preface Implementation ideas Ef...

A simple method to implement scheduled backup of MySQL database in Linux

Here are the detailed steps: 1. Check the disk sp...

Detailed introduction to MySQL database index

Table of contents Mind Map Simple understanding E...

MySQL5.7.21 decompressed version installation detailed tutorial diagram

Since I often install the system, I have to reins...

Detailed explanation of vuex persistence in practical application of vue

Table of contents vuex persistence Summarize vuex...

The difference between GB2312, GBK and UTF-8 in web page encoding

First of all, we need to understand that GB2312, ...

10 Tips to Improve Website Usability

Whether it is a corporate website, a personal blo...

Some tips on using the HTML title attribute correctly

If you want to hide content from users of phones, ...

Nginx cache configuration example

When developing and debugging a web application, ...

Implementation of mysql split function separated by commas

1: Define a stored procedure to separate strings ...

Sample code for implementing image drawer effect with CSS3

As usual, let’s first post the picture effect: Th...