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:
|
<<: Nginx uses ctx to realize data sharing and context modification functions
>>: How to prohibit vsftpd users from logging in through ssh
First we need to install some dependencies npm i ...
For record, it may be used in the future, and fri...
Dimensionality reduction of two-dimensional array...
I encountered a strange network problem today. I ...
background Indexes are a double-edged sword. Whil...
Recently, I made a function similar to shake, usi...
Carousel The main idea is: In the large container...
There are three pages A, B, and C. Page A contains...
JS implements a hover drop-down menu. This is a s...
In a complex table structure, some cells span mul...
This article example shares the specific code for...
MySQL is a relational database management system ...
MySQL foreign key constraint (FOREIGN KEY) is a s...
1.Jenkins installation steps: https://www.jb51.ne...
The Linux command to run the jar package is as fo...