Detailed tutorial on customizing the installation path of MySQL 5.7.18 (Binary Package installation) and Mysql5.7.18
Installation path:/application/mysql-5.7.18
1. Preparations
Mysql dependency
libaioyum install -y libaio
Create a mysql user and execute mysql as the user
useradd -s /bin/false -M mysql
Download and decompress the mysql Binary Package
cd /toolswget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gztar -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 provide a soft link to the mysql directory.
cd /application/mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql-5.7.18ln -s mysql-5.7.18/ mysql
Create mysql-files in the mysql directory with the permission of 750. recursively set the group and user of the mysql directory.
mkdir mysql/mysql-fileschmod 750 mysql/mysql-fileschown -R mysql:mysql mysql-5.7.18/
2. mysql directory operations
cd mysql
Initialize Database
A data directory is 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 in the returned result. My note is: wa0I: 1 w? V --
2017-04-28T02:49:00.853710Z 1 [Note] A temporary password is generated for root@localhost: wa0I:1w?V--a
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
Install ssl
bin/mysql_ssl_rsa_setup --datadir /application/mysql/data/
Path of the data Directory
Change 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 user of all other files is changed to root.
Modify configuration file
sed -i 's/^datadir=\/var\/lib\/mysql/datadir=\/application\/mysql\/data/g' /etc/my.cnfsed -i 's/^socket=\/var\/lib\/mysql\/mysql.sock/socket=\/tmp\/mysql.sock/g' /etc/my.cnfsed -i 's/^log-error=\/var\/log\/mariadb\/mariadb.log/log-error=\/application\/mysql\/data\/err.log/g' /etc/my.cnfsed -i 's/^pid-file=\/var\/run\/mariadb\/mariadb.pid/pid-file=\/application\/mysql\/data\/mysql.pid/g' /etc/my.cnf
It is equivalent:
vi /etc/my.cnfdatadir=/application/mysql/datasocket=/tmp/mysql.socklog-error=/application/mysql/data/err.logpid-file=/application/mysql/data/mysql.pid/etc/my.cnf Content:[mysqld]datadir=/application/mysql/datasocket=/tmp/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-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.logpid-file=/application/mysql/data/mysql.pid## include all files from the config directory#!includedir /etc/my.cnf.d
Copy the 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. It is troublesome.
sed -i 's/^basedir=/basedir=\/application\/mysql/g' /etc/init.d/mysqlsed -i 's/^datadir=/datadir=\/application\/mysql\/data/g' /etc/init.d/mysqlsed -i 's/^mysqld_pid_file_path=/mysqld_pid_file_path=\/application\/mysql\/data\/mysql.pid/g' /etc/init.d/mysql
Equivalent to dividing 45 and 46 rows
basedir=datadir=mysqld_pid_file_path=
Replace
basedir=/application/mysqldatadir=/application/mysql/datamysqld_pid_file_path=/application/mysql/data/mysql.pid
Method 2 (recommended ):
The idea is to replace the default address of the script (/usr/local/mysql) with the custom path (/application/mysql) without assigning a value to the variable.
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysql
Mysql can be started properly after installation.
3. End later
Command to create a soft link
Create a soft link from the mysql command to the environment variable directory so that you can find the corresponding command in the Variable
ln -s /application/mysql/bin/* /usr/local/sbin
Log on to mysql
[root@www mysql]# mysql -u root -p
Enter password: # Enter the previously saved random password drRR0
...
Mysql> # log on to the mysql Console
SQL statement for password Modification
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> quitBye[root@www mysql]#ormysql> ^DBye[root@www mysql]#
4. Common commands
Go to 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 customizing the installation path of MySQL 5.7.18 (Binary Package installation). I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!