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

Solve the problem of blank gap at the bottom of Img picture

When working on a recent project, I found that th...

CSS3 flip card number sample code

I received a task from the company today, and the...

Solve the problem of secure_file_priv null

Add secure_file_priv = ' '; then run cmd ...

Summary of all HTML interview questions

1. The role of doctype, the difference between st...

After reading the introduction of CSS box model, you will not be confused

The property names often heard in web design: con...

How to configure two or more sites using Apache Web server

How to host two or more sites on the popular and ...

Vue-cli framework implements timer application

Technical Background This application uses the vu...

Share 5 helpful CSS selectors to enrich your CSS experience

With a lot of CSS experience as a web designer, we...

How to make your browser talk with JavaScript

Table of contents 1. The simplest example 2. Cust...

Explanation of MySQL's horizontal and vertical table partitioning

In my previous article, I said that the optimizat...

How to implement mysql database backup in golang

background Navicat is the best MySQL visualizatio...

How to set up automatic daily database backup in Linux

This article takes Centos7.6 system and Oracle11g...

How to count the number of specific characters in a file in Linux

Counting the number of a string in a file is actu...

CentOS system rpm installation and configuration of Nginx

Table of contents CentOS rpm installation and con...