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

Vue3.0 adaptive operation of computers with different resolutions

First we need to install some dependencies npm i ...

Detailed explanation of several methods of JS array dimensionality reduction

Dimensionality reduction of two-dimensional array...

Analysis and description of network configuration files under Ubuntu system

I encountered a strange network problem today. I ...

MySQL 8 new features: Invisible Indexes

background Indexes are a double-edged sword. Whil...

Vue implements the shake function (compatible with ios13.3 and above)

Recently, I made a function similar to shake, usi...

Several methods of implementing carousel images in JS

Carousel The main idea is: In the large container...

iframe multi-layer nesting, unlimited nesting, highly adaptive solution

There are three pages A, B, and C. Page A contains...

Native JS to implement hover drop-down menu

JS implements a hover drop-down menu. This is a s...

HTML table tag tutorial (34): row span attribute ROWSPAN

In a complex table structure, some cells span mul...

JavaScript implements the generation of 4-digit random verification code

This article example shares the specific code for...

MySQL 5.7.17 installation and use graphic tutorial

MySQL is a relational database management system ...

MySQL foreign key constraint (FOREIGN KEY) case explanation

MySQL foreign key constraint (FOREIGN KEY) is a s...

How to forget the password of Jenkins in Linux

1.Jenkins installation steps: https://www.jb51.ne...

How to start jar package and run it in the background in Linux

The Linux command to run the jar package is as fo...