Mysql version 5.7. 18 (binary package installation) custom installation path tutorial details
- 2021-08-17 01:18:07
- OfStack
Installation path:/application/mysql-5. 7.18
1. Prepare
mysql dependency
libaio
yum install -y libaio
The user mysql is created and the mysql is executed as the user
useradd -s /bin/false -M mysql
Download and unzip the mysql2 binary package
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 name of mysql folder, and make a soft link to 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 under the mysql directory with permission 750, and 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. mysql in-directory operations
cd mysql
Initialize the database
It will generate an data directory in the mysql directory, which is the directory for storing the database
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 return 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 null, replace the--initialize option with the--initialize-insecure option
bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
Installing ssl
bin/mysql_ssl_rsa_setup --datadir /application/mysql/data/
Specify the path to the data directory
Change Owning Users and Groups
useradd -s /bin/false -M mysql
0
Except that the users of the data directory and the mysql-files directory under the mysql directory remain unchanged, the users of all other files are 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
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
useradd -s /bin/false -M mysql
3
Copy the startup program for mysql 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 variables provided by configuration files. More troublesome.
useradd -s /bin/false -M mysql
4
Equivalent to putting lines 45 and 46
useradd -s /bin/false -M mysql
5
Replace with
useradd -s /bin/false -M mysql
6
Method 2 (recommended):
The idea is to replace the default address of the script (/usr/local/mysql) with a custom path (/application/mysql) instead of assigning a value to the variable
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysql
From here, mysql can start normally after installation
3. Late end
Command to create a soft link
The mysql command creates a soft link to the directory of the environment variable, so that the user can find the corresponding command in the variable
ln -s /application/mysql/bin/* /usr/local/sbin
Login to mysql
useradd -s /bin/false -M mysql
9
Enter password: # Enter the previously saved random password drRR0
...
mysql > # Login to mysql console successfully
Modify password sql statement
mysql> alter user 'root'@'localhost' identified by 'NewPassWord';
# Change password to NewPassWord
Query OK, 0 rows affected (0.01 sec) # Modified successfully
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