Detailed tutorial on customizing the installation path of MySQL 5.7.18 version (binary package installation)

Detailed tutorial on customizing the installation path of MySQL 5.7.18 version (binary package installation)

Installation path: /application/mysql-5.7.18

1. Preliminary preparation

mysql dependency

libaio
yum install -y libaio

Create a user mysql and execute mysql as this user

useradd -s /bin/false -M mysql

Download the mysql binary package and unzip it

cd /tools
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /application/

Switch to the /application directory, shorten the mysql folder name, and make a soft link to the mysql directory

cd /application/
mv mysql-5.7.18-linux-glibc2.5-x86_64/mysql-5.7.18
ln -s mysql-5.7.18/mysql

Create mysql-files in the mysql directory. The folder permissions are 750. Recursively set the group and user of the mysql directory.

mkdir mysql/mysql-files
chmod 750 mysql/mysql-files
chown -R mysql:mysql mysql-5.7.18/

2. Operations in the mysql directory

cd mysql

Initialize the database

A data directory will be generated in the mysql directory to store the database directory

bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data

There is a random password at the end of the last line of the returned result. I wrote it down: wa0I:1w?V--a

2017-04-28T02:49:00.853710Z 1 [Note] A temporary password is generated for root@localhost: wa0I:1w?V--a

If you want to set the default password to empty, replace the --initialize option with the --initialize-insecure option.

bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data

Install ssl

bin/mysql_ssl_rsa_setup --datadir /application/mysql/data/

Specify the path to the data directory

Change the user and group

chown -R root .
chown -R mysql data mysql-files

Except for the data directory and mysql-files directory under the mysql directory, the owner of all other files is changed to root.

Modify the configuration file

sed -i 's/^datadir=\/var\/lib\/mysql/datadir=\/application\/mysql\/data/g' /etc/my.cnf
sed -i 's/^socket=\/var\/lib\/mysql\/mysql.sock/socket=\/tmp\/mysql.sock/g' /etc/my.cnf
sed -i 's/^log-error=\/var\/log\/mariadb\/mariadb.log/log-error=\/application\/mysql\/data\/err.log/g' /etc/my.cnf
sed -i 's/^pid-file=\/var\/run\/mariadb\/mariadb.pid/pid-file=\/application\/mysql\/data\/mysql.pid/g' /etc/my.cnf

is equivalent to:

vi /etc/my.cnf
datadir=/application/mysql/data
socket=/tmp/mysql.sock
log-error=/application/mysql/data/err.log
pid-file=/application/mysql/data/mysql.pid
/etc/my.cnf Content:
[mysqld]
datadir=/application/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/application/mysql/data/err.log
pid-file=/application/mysql/data/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

Copy Startup Program

cp support-files/mysql.server /etc/init.d/mysql

Copy the mysql startup program to the /etc/init.d/ directory to start the program

Edit the startup file and configure the startup directory

Method 1:

The idea is to assign values ​​to the variables provided by the configuration file. More troublesome.

sed -i 's/^basedir=/basedir=\/application\/mysql/g' /etc/init.d/mysql
sed -i 's/^datadir=/datadir=\/application\/mysql\/data/g' /etc/init.d/mysql
sed -i 's/^mysqld_pid_file_path=/mysqld_pid_file_path=\/application\/mysql\/data\/mysql.pid/g' /etc/init.d/mysql

This is equivalent to replacing lines 45 and 46.

basedir=
datadir=
mysqld_pid_file_path=

Replace with

basedir=/application/mysql
datadir=/application/mysql/data
mysqld_pid_file_path=/application/mysql/data/mysql.pid

Method 2 (recommended):

The idea is to directly replace the default address of the script (/usr/local/mysql) with a custom path (/application/mysql) so that there is no need to assign a value to the variable.

sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysql

At this point, mysql installation is complete and can be started normally

3. Late ending

Command to create soft link

Create a soft link from the mysql command to the directory of the environment variable so that users can find the corresponding command in the variable

ln -s /application/mysql/bin/* /usr/local/sbin

Login to mysql

[root@www mysql]# mysql -u root -p

Enter password: #Enter the random password drRR0 saved previously

...

mysql> #Successfully logged into the mysql console

Change password sql statement

mysql> alter user 'root'@'localhost' identified by 'NewPassWord';

#Change the password to NewPassWord

Query OK, 0 rows affected (0.01 sec) #Modification successful

Type quit or Ctrl+d to exit

mysql> quit
Bye
[root@www mysql]#
or
mysql> ^DBye
[root@www mysql]#

4. Common commands

Enter mysql

mysql -u root -p

Start mysql

service mysql start

Stop mysql

service mysql stop

Restart mysql

service mysql restart

The above is a detailed tutorial on custom installation path of MySQL 5.7.18 version (binary package installation) introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL 5.7.18 binary package installation tutorial under Linux (without default configuration file my_default.cnf)
  • Deploy MySQL 5.7.17 binary installation and multi-instance configuration on CentOS 6.5
  • How to install mysql5.7.24 binary version on Centos 7 and how to solve it
  • Centos7.5 installs mysql5.7.24 binary package deployment
  • Detailed tutorial on installing MySQL 5.7.11 for Linux Generic binary version in CentOS 7 via command line
  • Tutorial on installing MySQL 5.6.20 using Linux binary universal package
  • Install mysql5.6 in ubuntu system (through binary)
  • mysql 5.7.19 latest binary installation
  • MySQL 5.6.24 (binary) automatic installation script under Linux
  • The whole process record of MySQL binary installation and backup

<<:  Nginx uses ctx to realize data sharing and context modification functions

>>:  How to prohibit vsftpd users from logging in through ssh

Recommend

MySQL trigger trigger add, delete, modify and query operation example

This article uses examples to describe the add, d...

MySQL trigger principle and usage example analysis

This article uses examples to explain the princip...

Use js to write a simple snake game

This article shares the specific code of a simple...

How to make full use of multi-core CPU in node.js

Table of contents Overview How to make full use o...

In-depth explanation of nginx location priority

location expression type ~ indicates to perform a...

An article to help you understand the basics of VUE

Table of contents What is VUE Core plugins in Vue...

Implementation and usage scenarios of JS anti-shake throttling function

Table of contents 1. What is Function Anti-shake?...

Detailed explanation of docker-machine usage

Docker-machine is a Docker management tool offici...

CSS3 timeline animation

Achieve results html <h2>CSS3 Timeline</...

Apache Spark 2.0 jobs take a long time to finish when they are finished

Phenomenon When using Apache Spark 2.x, you may e...

How to pull the docker image to view the version

To view the version and tag of the image, you nee...

Analysis of MySQL example DTID master-slave principle

Table of contents 1. Basic Concepts of GTID 2. GT...

Docker container connection implementation steps analysis

Generally speaking, after the container is starte...

CentOS 7.9 installation and configuration process of zabbix5.0.14

Table of contents 1. Basic environment configurat...