Directory preparation running environment confirm your installation Version Download MySQL install MySQL prepare installation environment compile and install configuration MySQL Single Instance configuration method
Directory preparation running environment confirm your installation Version Download MySQL install MySQL prepare installation environment compile and install configuration MySQL Single Instance configuration method
Directory
Preparations
Running Environment
Confirm your installation version
Download MySQL
Install MySQL
Prepare the installation environment
Compile and install
Configure MySQL
Single Instance Configuration
Configuration method for a single instance
Add Firewall
Start MySQL
Restart MySQL
Multi-instance Configuration
What is multi-instance
Multi-instance configuration method
Create a Startup File
Initialize Database
Configure Firewall
Start MySQL
Log on to MySQL
Restart MySQL
Preparations
Running Environment
The running environment of this article is as follows:
System Version
CentOS7 minimal 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 your installation version
Mysql is divided into development version and stable version (GA). The development version has the latest features, but it is not stable and has not been completely tested. It may have serious bugs, stable versions have been tested for a long time, eliminating known bugs, and their stability and security are guaranteed.
For a mysql version such as: mysql-5.6.1-m1, what does this version mean?
1. Explanation for 5.6.1: the first digit 5 represents the file format, the second digit 6 represents the release level, and the third digit 1 represents the version number. The last number is increased when the update range is small. When a major feature is updated, the second number is increased. When the file format is changed, the first number is increased.
2. explanation for m1: This indicates the stability level of the mysql version. Without this suffix, this version is a stable version (GA ); if the suffix is mN (such as m1, m2) format, it indicates that this version has added some new features that have been thoroughly tested and can be considered as a pilot production mold; if the suffix is rc, it indicates that this is a candidate version and important known bugs have been modified. However, it has not been used for a long time to confirm that all bugs have been fixed.
Once you select the version number, you must select which release version to use. You can use a binary release, such as an RPM package or a Zip package. However, if you want to implement the following functions, you must select the source code installation method (this article selects the source code Installation Method ):
1. l install mysq to the specified location
2. l use some features of mysql (not available in standard binary versions), such as TCP packet support and debugging of 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 to make the installed mysql smaller.
Download mysql
Download mysql here:
I chose this:
After the download, check the MD5 of the file to check whether the original version is downloaded from the official website (to prevent tampering with the software)
After downloading it from windows and uploading it to linux, run the md5sum command to check:
[Root @ localhost src] # md5sum mysql-5.6.25.tar.gz
37664399c91021abe070faa700ecd0ed mysql-5.6.25.tar.gz
It can be seen that it is consistent with the MD5 in. If it is inconsistent, you need to change the image address to download mysql.
Install mysql
Prepare the installation environment
First, check whether mysql has been installed:
[Root @ localhost src] # rpm-qa | grep mysql
If yes, uninstall the previously installed mysql:
[Root @ localhost src] # rpm-e -- nodeps xxx (xxx is the search result)
Delete all related files:
/Etc/my. cnf
Compile and install
Install the package required for compiling code
[Root @ localhost src] # yum-y install make gcc-c ++ cmake bison-devel ncurses-devel libaio
[Root @ localhost src] # yum install libaio-devel-y
[Root @ localhost src] # yum install perl-Data-Dumper-y
[Root @ localhost src] # yum install net-tools-y
Decompress the installation package and compile and install it
[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. 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
So far, mysql installation is complete
Configure mysql
Check whether there are mysql users in the system. 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 on to the system using the mysql account)
[Root @ localhost mysql-5.6.25] # groupadd mysql-s/sbin/nologin
[Root @ localhost mysql-5.6.25] # useradd-g mysql
Modify permissions
[Root @ localhost mysql-5.6.25] # chown-R mysql: mysql/usr/local/mysql
So far, mysql installation is complete
The following two configuration methods are available:
Single Instance Configuration
Configuration method for a single instance
Enter the installation path
[Root @ localhost mysql-5.6.25] # cd/usr/local/mysql
Go to 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, I will be searched in certain order. cnf, which is first found in the/etc directory. If no cnf is found, "$ basedir/my. cnf ", in this example/usr/local/mysql/my. cnf, which is the default location of the new MySQL configuration file!
Note: After the minimal installation of the CentOS 7 operating system is completed, a my. cnf, 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 MySQL installed by source code, resulting in startup failure.
After updating the system using "yum update", you need to check whether there will be an extra my. cnf in The/etc directory. If there are more, rename it to something else. Otherwise, MySQL will use this configuration file to start, which may cause problems such as failure to start normally.
Add Firewall
[Root @ localhost mysql] # firewall-cmd -- zone = public -- add-port = 3306/tcp -- permanent
[Root @ localhost mysql] # firewall-cmd -- reload
Start mysql
Add the service, copy the service script to the init. d directory, and set startup
[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 whether mysql is successfully started.
[Root @ localhost mysql] # netstat-lntp | grep 3306
If mysql is not successfully started, check the error log in the/usr/local/mysql/data directory.
[Root @ localhost data] # tail localhost. localdomain. err (localhost. localdomain is the host name)
If no log directory is generated, mysql installation fails (re-compile and install)
Restart mysql
First, kill the mysql process.
[Root @ localhost 3306] # pkill mysqld
Then, check whether the mysql process has been killed.
[Root @ localhost3306] # netstat-lntp | grep 3306
At this time, shell has no output, indicating that the mysql process has been killed.
Then restart mysql and check whether the startup is successful again.
[Root @ localhost 3306] # service mysql start
[Root @ localhost3306] # netstat-lntp | grep 3306
Multi-instance Configuration
What is multi-instance
Simply put, it is to enable multiple service ports on one machine and run multiple mysql service processes. These service processes provide their own services by listening to different service ports through different sockets.
These mysql multiple instances share a set of mysql installation programs, using different my. the cnf configuration file, Startup Program, and data file are logically independent of multiple instances when providing services, to obtain the hardware resources of related servers.
Multi-instance configuration method
In this article, enable two ports on mysql (3306 and 3307 to configure multiple instances, because the following master-slave synchronization uses these two ports for simulation)
Create directory (the log directory is the place where mysql logs are stored)
[Root @ localhost mysql] # mkdir-p/data/{3306, 3307}/data
[Root @ localhost mysql] # mkdir-p/data/{3306, 3307}/log
Create my. cnf in/data/3306
[Root @ localhost mysql] # cd/data/3306
[Root @ localhost mysql] # vi my. cnf
Copy the following content to the file.
[Client]
Port = 3306
Socket =/data/3306/mysql. sock