Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql-5.7.18 Custom installation path handout

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the mysql-5.7.18 custom installation path handout, which involves things, learned from the theoretical knowledge, there are many books, literature for your reference, from a practical point of view, accumulated years of practical experience can be shared with you.

1. Prepare mysql dependencies in advance

Libaio

Yum install-y libaio

Create a user mysql to execute mysql as that user

Useradd-s / bin/false-M mysql

Download the mysql binary package and extract 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/

Change 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 a mysql-files under the mysql directory with 750permissions for this folder, 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/

Operations in 2.mysql directory

Cd mysql

Initialize the database

A data directory is generated within the mysql directory, where the database is stored

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 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 users and groups you belong to

Chown-R root.

Chown-R mysql data mysql-files

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

Cp support-files/mysql.server / etc/init.d/mysql

Copy the startup program of 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 the variables provided by the configuration file. It's 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

It is equivalent to putting 45 and 46 lines

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 you don't have to assign a value to the variable

Sed-I-I

After the installation of mysql is completed, you can start normally.

3. Post-end command to create soft links

Create a soft link mysql command 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

Log in to mysql

[root@www mysql] # mysql-u root-p

Enter password: # enter the previously saved random password drRR0 # successfully log in to 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.01sec) # 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

Read the above mysql-5.7.18 custom installation path handout introduction, I hope it can bring some help to everyone in practical application. Due to the limited space in this article, there will inevitably be deficiencies and areas that need to be supplemented. You can continue to pay attention to the industry information section and will update your industry news and knowledge regularly. If you need more professional answers, you can contact us on the official website for 24-hour pre-sales and after-sales to help you answer questions at any time.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report