Compile and install MySQL5.7.9 from Linux source code

Source: Internet
Author: User

Compile and install MySQL5.7.9 from Linux source code

I. Environment preparation:

I have tried the following environments:
1. Minimize the default installation of CentOS6.7 minimal images;
2. RedHat6.5 install the basic DVD server;
3. Other Linux versions are not verified.
Note that after the system is installed, You need to configure the NIC and disable the firewall and SELINUX:
# Disable Linux Firewall commands
# Chkconfig iptables off
# Modify SELINUX Configuration
# Vim/etc/sysconfig/selinux
SELINUX = enforcing
To:
SELINUX = disabled
After modification, save and exit, and then restart the system.

Ii. upgrade the system:

Use the yum-y update command to upgrade the system to the latest version.
If the server is on the Intranet, skip this step.

3. Make some preparations (the following Linux commands are executed by su to the root user ):

1. New mysql user group
# Groupadd mysql
2. New mysql users
# Useradd-r-g mysql
3. Create a new database execution file directory (the compiled mysql program will be installed in this directory later)
# Mkdir-p/usr/local/mysql
4. Create a database data file directory
# Mkdir-p/home/mysql
# Mkdir-p/home/mysql/data
# Mkdir-p/home/mysql/logs
# Mkdir-p/home/mysql/temp
Note: The above 3rd and 4th are used to separate the MySQL data file from the execution program file. If you want to set it to a different path, modify the corresponding execution command and database initialization script!
5. Edit the PATH search PATH
# Vi/etc/profile +
# Add two lines at the end of the profile file
PATH =/usr/local/mysql/bin:/usr/local/mysql/lib: $ PATH
Export PATH
Make the PATH search PATH take effect immediately:
# Source/etc/profile
6. Edit the hosts file, add a line, and add the local IP address and Host Name (you need to modify the IP address and host name as needed)
# Vi/etc/hosts +
192.168.1.2 bkjia
7. Install the tools and libraries required for compiling the source code. (If you cannot install the source code online, you must configure the source code in advance. If you want to configure the source code in the local environment, you can try it later)
# Yum-y install wget gcc-c ++ ncurses-devel cmake make perl
NOTE: If RedHat5.4 does not have cmake in its ISO source, you can manually compile and install cmake, or upgrade to RedHat5.9 before installing cmake in the source yum.
Transfer the mysql-5.7.9.tar.gz source package to the/usr/local/src path through ftpor sftp.
If the server can access the Internet, you can download mysql-5.7.9.tar.gz through wget. As follows:
# Cd/usr/local/src
# Wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

Four, start to compile and install mysql-5.7.9:

1. Go to the source code compressed package download directory
# Cd/usr/local/src
2. decompress the source code package
# Tar-zxvf mysql-5.7.9.tar.gz
3. Go to the extract source code directory.
# Cd mysql-5.7.9
4. Use the cmake source code to install mysql. (If you want to install mysql in different paths, modify the path/usr/local/mysql in the following statement !)
# Cmake \
-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \
-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE = 1 \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DWITH_ARCHIVE_STORAGE_ENGINE = 1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE = 1 \
-DWITH_MEMORY_STORAGE_ENGINE = 1 \
-DWITH_READLINE = 1 \
-DENABLED_LOCAL_INFILE = 1 \
-DMYSQL_DATADIR =/home/mysql/data \
-DMYSQL_USER = mysql \
-DMYSQL_TCP_PORT = 3306 \
-DENABLE_DOWNLOADS = 1
After the above copies are complete, press enter and start the cmake process. Generally, the time will not be long.
5. Compile the source code after cmake is complete. This step takes a long time. Please wait.
# Make
6. Install the compiled program
# Make install
Note: If you need to reinstall mysql, In the/usr/local/src/mysql-5.7.9 in the execution of make install can be done, no need to cmake and make
7. Clear the temporary installation file
# Make clean
8. Modify the directory owner
# Chown-Rf mysql: mysql/usr/local/mysql
# Chown-Rf mysql: mysql/home/mysql
9. Enter the installation path of the mysql execution Program
# Cd/usr/local/mysql
10. Execute the initialization configuration script to create the database and table that comes with the system (note that the path/home/mysql/data must be replaced with the custom database storage path)
# Scripts/mysql_install_db -- user = mysql -- datadir =/home/mysql/data
# The configuration file my. cnf is generated under the/usr/local/mysql/initialization script. You need to change the owner of the configuration file:
# Chown-Rf mysql: mysql/usr/local/mysql
Note:
(1) Tips: when starting the MySQL service, I will be searched in certain order. cnf, which is first found in the/etc directory. If it cannot be found, the mysql program directory will be searched for my. cnf ";
(2) note that after the minimal installation of CentOS 6.4 operating system is complete, even if mysql is not installed, there will be a my In the/etc directory. cnf file. We recommend that you rename this file to another name. Otherwise, this file will interfere with the correct configuration of MySQL installed in the source code, resulting in a failure to start. Modify/etc/my. cnf as follows:
# Mv/etc/my. cnf/etc/my. cnf. bak
# Of course, you can also delete the/etc/my. cnf file:
# Rm/etc/my. cnf
(3) If you need to use it in the production environment, do not rush to start the following mysql. We recommend that you delete the/usr/local/mysql. cnf file generated during mysql initialization in the previous step, and then put the mysql configuration file my. cnf you optimized under/etc. (This is my experience in mysql master-slave replication and mysql optimization !)
11. Copy the Service Startup Script
# Cp/usr/local/mysql/support-files/mysql. server/etc/init. d/mysql
12. Start the MySQL Service
# Service mysql start
13. Set the Automatic startup Service
# Chkconfig mysql on
14. log on to and modify the MySQL user root password
# Mysql-u root
Mysql> use mysql;
Mysql> grant all privileges on *. * TO root @ "%" identified by "123456 ";
Mysql> update user set Password = password ('000000') where User = 'root ';
Mysql> flush privileges;
Mysql> exit;
15. Check whether the MySQL user root password has taken effect in the previous step:
[Root @ bkjia etc] # mysql-u root
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO) -- logon fails without a password, indicating that the password has been modified successfully.
[Root @ bkjia ~] # Mysql-u root-p
Enter password: -- Enter your mysql root Account password when prompted
# The following message is displayed when logon is successful:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 422
Server version: 5.7.9-log Source distribution
Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
Mysql>
16. (optional) run the Security Settings script. It is strongly recommended that the production server:
[Root @ bkjia ~] #/Usr/local/mysql/bin/mysql_secure_installation

NOTE: running all parts of this script is recommended for all MySQL
Servers in production use! Please read each step carefully!

In order to log into MySQL to secure it, we'll need the current
Password for the root user. If you 've just installed MySQL, and
You haven't set the root password yet, the password will be blank,
So you shoshould just press enter here.

Enter current password for root (enter for none ):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
Root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n '.

Change the root password? [Y/n] n --------------- enter n here
... Skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
To log into MySQL without having to have a user account created
Them. This is intended only for testing, and to make the installation
Go a bit smoother. You shoshould remove them before moving into
Production environment.

Remove anonymous users? [Y/n] Y --------------- enter Y here
... Success!

Normally, root shoshould only be allowed to connect from 'localhost'. This
Ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n --------------- enter n here
... Skipping.

By default, MySQL comes with a database named 'test' that anyone can
Access. This is also intended only for testing, and shocould be removed
Before moving into a production environment.

Remove test database and access to it? [Y/n] Y --------------- enter Y here
-Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn' t exist
... Failed! Not critical, keep moving...
-Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
Will take effect immediately.

Reload privilege tables now? [Y/n] Y --------------- enter Y here
... Success!

All done! If you 've completed all of the above steps, your MySQL
Installation shoshould now be secure.

Thanks for using MySQL!

Cleaning up...
17. Restart the server and check whether mysql can be automatically started upon startup.
[Root @ bkjia ~] # Reboot

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.