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

The process of installing MySQL5.6 with source code under CentOS 7

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the "CentOS 7 source code installation process of MySQL5.6" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Catalogue

Preparatory work

Operation environment

Confirm the version to be installed

Download MySQL

Install MySQL

Prepare the installation environment

Compile and install

Configure MySQL

Single instance configuration

Single instance configuration method

Add Firewall

Start MySQL

Restart MySQL

Multi-instance configuration

What is multiple instances?

Multi-instance configuration method

Create a startup file

Initialize the database

Configure the firewall

Start MySQL

Log in to MySQL

Restart MySQL

Preparatory work

Operation environment

The running environment of this paper is as follows

System version

CentOS 7 minimized installation:

Linux version 3.10.0-123.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)) # 1 SMP Mon Jun 30 12:09:22 UTC 2014

Mysql version

Mysql-5.6.25

Confirm the version to be installed

Mysql is divided into development version and stable version (GA). The development version has the latest features, but it is unstable and has not been fully tested, so there may be serious bug, while the stable version has been tested for a long time to eliminate the known bug, and its stability and security are guaranteed to a certain extent.

What does this version number mean for a mysql version number such as mysql-5.6.1-m1?

1. Explanation for 5.6.1: the first number 5 represents the file format, the second number 6 represents the release level, and the third number 1 represents the version number. When the update range is small, the final number will increase, when there is a major feature update, the second number will increase, and when the file format changes, the first number will increase.

two。 Explanation for M1: this is used to indicate the stability level of this mysql version. Without this suffix, then this version is a stable version (GA); if the suffix is mN (for example, M1 score m2) format, it indicates that this version has added some new features that have been thoroughly tested, and it can be considered as a trial production mold. If the suffix is rc, this is a candidate version, and the known important bug has been modified, but it has not been used long enough to confirm that all bug has been fixed.

Once you have selected the version number, you should choose which distribution to use. You can use binary distributions such as RPM packages or Zip packages, but if you want to achieve the following features, you need to choose source code installation (this article is the way to choose source code installation):

1.l install mysq to the specified location

2.l use some of the features of mysql (which are not available in the standard binary version) such as TCP packet support, debug mysql

3. All character sets are supported by default in the binary version, but you can specify the character set when compiling and installing the source code, thus making the installed mysql smaller.

Download MySQL

Download mysql: http://dev.mysql.com/downloads/mysql/ here

I chose this:

After downloading, you need to check the MD5 of the file to confirm whether the original version downloaded from the official website (in case the software has been tampered with)

After downloading from windows and uploading to linux, use the md5sum command to check:

[root@localhost src] # md5sum mysql-5.6.25.tar.gz

37664399c91021abe070faa700ecd0ed mysql-5.6.25.tar.gz

As you can see, it is consistent with the MD5 in the image above. If it is not consistent, change a mirror address to download mysql.

Install MySQL

Prepare the installation environment

First check to see if mysql has been installed:

[root@localhost src] # rpm-qa | grep mysql

If so, uninstall the previously installed mysql:

[root@localhost src] # rpm-e-- nodeps xxx (xxx is the search result)

And delete all related files:

/ etc/my.cnf

Compile and install

Install the packages required to compile the code

[root@localhost src] # yum-y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel perl-Data-Dumper net-tools

Extract the installation package and compile the installation

[root@localhost src] # tar xvf mysql-5.6.25.tar.gz

[root@localhost src] # cd mysql-5.6.25

[root@localhost mysql-5.6.25] # cmake\

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_DATADIR=/usr/local/mysql/data\

-DSYSCONFDIR=/etc\

-DWITH_MYISAM_STORAGE_ENGINE=1\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_MEMORY_STORAGE_ENGINE=1\

-DWITH_READLINE=1\

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock\

-DMYSQL_TCP_PORT=3306\

-DENABLED_LOCAL_INFILE=1\

-DWITH_PARTITION_STORAGE_ENGINE=1\

-DEXTRA_CHARSETS=all\

-DDEFAULT_CHARSET=utf8\

-DDEFAULT_COLLATION=utf8_general_ci

Compiled successfully

[root@localhost src] # make & & make install

At this point, the mysql installation is complete

Configure MySQL

Check whether the system already has a mysql user, and if not, create

[root@localhost mysql-5.6.25] # cat / etc/passwd | grep mysql

[root@localhost mysql-5.6.25] # cat / etc/group | grep mysql

Create a mysql user (but cannot log in to the system using a mysql account)

[root@localhost mysql-5.6.25] # groupadd mysql- s / sbin/nologin

[root@localhost mysql-5.6.25] # useradd-g mysql mysql

Modify permissions

[root@localhost mysql-5.6.25] # chown-R mysql:mysql / usr/local/mysql

At this point, mysql is installed.

There are two configuration methods below. It is recommended to configure multiple instances.

Single instance configuration

Single instance configuration method

Enter the installation path

[root@localhost mysql-5.6.25] # cd / usr/local/mysql

Enter the installation path, execute the initialization configuration script, and create the database and table that comes with the system.

[root@localhost mysql] # scripts/mysql_install_db-basedir=/usr/local/mysql-datadir=/usr/local/mysql/data-user=mysql

Note: when starting the MySQL service, the my.cnf will be searched in a certain order, first in the / etc directory, and if it cannot be found, it will search for "$basedir/my.cnf", in this case / usr/local/mysql/my.cnf, which is the default location of the configuration file for the new version of MySQL!

Note: after the minimum installation of the CentOS version 7 operating system is completed, there will be a my.cnf in the / etc directory. You need to rename this file to another name, such as / etc/my.cnf.bak, otherwise, the file will interfere with the correct configuration of the MySQL installed by the source code, resulting in failure to boot.

After updating the system with "yum update", you need to check to see if there is an extra my.cnf in the / etc directory, and if so, rename it to something else. Otherwise, MySQL will start with this configuration file, which may cause problems such as not starting properly.

Add Firewall

[root@localhost mysql] # firewall-cmd-zone=public-add-port=3306/tcp-permanent

[root@localhost mysql] # firewall-cmd-- reload

Start mysql

Add services, copy service scripts to the init.d directory, and set boot up

[root@localhost mysql] # cp support-files/mysql.server / etc/init.d/mysql

[root@localhost mysql] # chkconfig mysql on

[root@localhost mysql] # service mysql start-- start MySQL

Check to see if mysql starts successfully

[root@localhost mysql] # netstat-lntp | grep 3306

If mysql does not start successfully, go to the directory / usr/local/mysql/data to view the error log

[root@localhost data] # tail localhost.localdomain.err (localhost.localdomain is the hostname)

If the log directory is not generated, the mysql installation is not successful (recompile and install again)

Restart mysql

Kill the mysql process first

[root@localhost 3306] # pkill mysqld

Then check if the mysql process has been killed

[root@localhost 3306] # netstat-lntp | grep 3306

At this point, shell has no output, indicating that the mysql process has been killed

Then restart mysql and check again to see if it started successfully

[root@localhost 3306] # service mysql start

[root@localhost 3306] # netstat-lntp | grep 3306

Multi-instance configuration

What is multiple instances?

To put it simply, it is to open multiple different service ports on a machine and run multiple mysql service processes, which provide their own services by listening to different service ports through different socket.

These mysql multiple instances share a set of mysql installers, using different my.cnf configuration files, startup programs, and data files. When providing services, multiple instances appear to be logically independent, and multiple instances obtain the hardware resources of the relevant servers according to the set values of the configuration files.

Multi-instance configuration method

In this article, multiple instances are configured by opening two ports (3306 and 3307) on mysql, because the following master-slave synchronization uses these two ports to simulate)

Create a directory (the log directory is where mysql logs are stored)

[root@localhost mysql] # mkdir-p / data/ {3306 3307} / data

[root@localhost mysql] # mkdir-p / data/ {3306 3307} / log

Create a new my.cnf in / data/3306

[root@localhost mysql] # cd / data/3306

[root@localhost mysql] # vim my.cnf

Copy the following to the file

[client]

Port = 3306

Socket = / data/3306/mysql.sock

[mysqld]

Port=3306

Socket = / data/3306/mysql.sock

Pid-file = / data/3306/data/mysql.pid

Basedir = / usr/local/mysql

Datadir = / data/3306/data

Server-id=1

# log-bin=mysql-bin

# log-bin-index= mysql-bin.index

# LOGGING

Log_error=/data/3306/log/mysql-error.log

Slow_query_log_file=/data/3306/log/mysql-slow.log

Slow_query_log=1

Similarly, create a new my.cnf in / data/3307

[root@localhost mysql] # cd / data/3307

[root@localhost mysql] # vim my.cnf

Copy the following into the file (change the above 3306 to 3307, and the value of server-id)

[client]

Port = 3307

Socket = / data/3307/mysql.sock

[mysqld]

Port=3307

Socket = / data/3307/mysql.sock

Pid-file = / data/3307/data/mysql.pid

Basedir = / usr/local/mysql

Datadir = / data/3307/data

Server-id=3

# log-bin=mysql-bin

# log-bin-index= mysql-bin.index

# LOGGING

Log_error=/data/3307/log/mysql-error.log

Slow_query_log_file=/data/3307/log/mysql-slow.log

Slow_query_log=1

Check the directory structure to see if the files have been misplaced

[root@localhost 3307] # tree / data

/ data

├── 3306

│ ├── data

│ ├── log

│ └── my.cnf

└── 3307

│ ├── data

│ ├── log

│ └── my.cnf

Create a startup file

Create a new mysql startup file in / data/3306

[root@localhost mysql] # cd / data/3306

[root@localhost mysql] # vim mysql

Copy the following to the file

#! / bin/sh

Port=3306

Mysql_user= "root"

Mysql_pwd= ""

CmdPath= "/ usr/local/mysql/bin"

# startup function

Function_start_mysql ()

{

Printf "Starting MySQL...\ n"

/ bin/sh ${CmdPath} / mysqld_safe-- defaults-file=/data/$ {port} / my.cnf 2 > & 1 > / dev/null &

}

# stop function

Function_stop_mysql ()

{

Printf "Stoping MySQL...\ n"

${CmdPath} / mysqladmin-u ${mysql_user}-p$ {mysql_pwd}-S / data/$ {port} / mysql.sock shutdown

}

# restart function

Function_restart_mysql ()

{

Printf "Restarting MySQL...\ n"

Function_stop_mysql

Sleep 2

Function_start_mysql

}

Case $1 in

Start)

Function_start_mysql

Stop)

Function_stop_mysql

Restart)

Function_restart_mysql

*)

Printf "Usage: / data/$ {port} / mysql {start | stop | restart}\ n"

Esac

Similarly, create a new mysql startup file in / data/3307

[root@localhost mysql] # cd / data/3307

[root@localhost mysql] # vi mysql

Copy the following to the file

#! / bin/bash

Port=3307

Mysql_user= "root"

Mysql_pwd= ""

CmdPath= "/ usr/local/mysql/bin"

# startup function

Function_start_mysql ()

{

Printf "Starting MySQL...\ n"

/ bin/sh ${CmdPath} / mysqld_safe-- defaults-file=/data/$ {port} / my.cnf 2 > & 1 > / dev/null &

}

# stop function

Function_stop_mysql ()

{

Printf "Stoping MySQL...\ n"

${CmdPath} / mysqladmin-u ${mysql_user}-p$ {mysql_pwd}-S / data/$ {port} / mysql.sock shutdown

}

# restart function

Function_restart_mysql ()

{

Printf "Restarting MySQL...\ n"

Function_stop_mysql

Sleep 2

Function_start_mysql

}

Case $1 in

Start)

Function_start_mysql

Stop)

Function_stop_mysql

Restart)

Function_restart_mysql

*)

Printf "Usage: / data/$ {port} / mysql {start | stop | restart}\ n"

Esac

Modify file owner and permissions

[root@localhost 3307] # chown-R mysql:mysql / data

[root@localhost 3307] # find / data-name mysql-exec chmod 700 {}\

Add mysql startup path

[root@localhost 3307] # echo 'export PATH=$PATH:/usr/local/mysql/bin' > > / etc/profile

[root@localhost 3307] # source / etc/profile

[root@localhost 3307] # echo $PATH

/ usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

You can see that the mysql path has been added to the startup path

Initialize the database

[root@localhost scripts] # cd / usr/local/mysql/scripts

[root@localhost scripts] # / mysql_install_db-- defaults-file=/data/3306/my.cnf-- user=mysql-- basedir=/usr/local/mysql-- datadir=/data/3306/data

[root@localhost scripts] # / mysql_install_db-- defaults-file=/data/3307/my.cnf-- user=mysql-- basedir=/usr/local/mysql-- datadir=/data/3307/data

Configure the firewall

[root@localhost scripts] # firewall-cmd-zone=public-add-port=3306/tcp-permanent

Success

[root@localhost scripts] # firewall-cmd-zone=public-add-port=3307/tcp-permanent

Success

[root@localhost scripts] # firewall-cmd-- reload

Success

Start mysql

Start two ports respectively

[root@localhost scripts] # / data/3306/mysql start

Starting MySQL...

[root@localhost scripts] # / data/3307/mysql start

Starting MySQL...

[root@localhost scripts] # netstat-lntp | grep 330

Tcp6 0 0: 3306: * LISTEN 33556/mysqld

Tcp6 0 0: 3307: * LISTEN 34204/mysqld

You can see that both ports have been started successfully

Log in to MySQL

The newly installed mysql does not have a login password.

[root@localhost scripts] # mysql-S / data/3306/mysql.sock

If unsuccessful, check the mysql-error.log log in the / data/3306/log directory and troubleshoot the errors one by one

If the login is successful, change the login password below (it is not recommended to change the password in the shell environment, otherwise others can see the password simply by looking at the command history (provided you do not have a case command history).

Mysql > update mysql.user set password=password ("123456") where user='root'

Mysql > flush privileges

By the same token, use the above method to change the login password of 3307

Write the above changed password back to the startup file of mysql (otherwise enter the password every time you start, shut down, and restart mysql)

[root@localhost 3306] # sed-I data/3306/mysql MySQL data/3306/mysql pwd =\ "\" / mysql_pwd=\ "123456\" / g' /

[root@localhost 3306] # sed-I data/3307/mysql MySQL data/3307/mysql pwd =\ "\" / mysql_pwd=\ "123456\" / g' /

Pay attention to change the above 123456 to the set password

Restart mysql

[root@localhost 3306] # / data/3306/mysql restart

[root@localhost 3306] # netstat-lntp | grep 330

Tcp6 0 0: 3306: * LISTEN 35430/mysqld

You can see that port 3306 is restarted successfully, and port 3307 can be restarted in the same way.

At this point, mysql-5.6.25 is installed on CentOS7

This is the end of the content of "the process of installing MySQL5.6 in the source code under CentOS 7". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Database

Wechat

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

12
Report