Mysql source code compilation tutorial post, mysql source code compilation tutorial

Source: Internet
Author: User

Mysql source code compilation tutorial post, mysql source code compilation tutorial

Digress: This is a tutorial post, not only learning mysql compilation, but also some compilation knowledge. I am also a cainiao. I want to write some insights and experiences. If you have any questions, I can criticize and correct them. Thank you!

If you only want to install Mysql, move to another installation post: Mysql installation post.

Environment:
OS: CentOS 6.6x64 mini
Mysql: mysql-5.6.25
1. mysql download:
Http://dev.mysql.com/downloads/mysql/
Note: This website is sometimes vulnerable to JS attacks. If you select Source Code, you will not be able to respond. Therefore, you can flip over Q or directly click the link below.
: Http: // 101.44.1.118/files/90110000038859AB/nchc.dl.sourceforge.net/project/mysql.#/mysql%205.6.25/mysql-5.6.25.tar.gz

2. installation:

☆Disable Selenge

★Run the following command to obtain selinux:

[root@centos ~]# getenforce Disabled

Disabled has been Disabled. You can skip this step.

Enforcing Enabled

Permissive temporary disabling

★Use the following command to disable selinux (the first is temporarily disabled, and the second is permanently disabled)

[root@centos ~]# setenforce 0[root@centos ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

★Check whether the modification is correct.

[root@centos ~]# getenforce Permissive [root@centos ~]# cat /etc/selinux/config

Make sure SELINUX = disabled (The selinux configuration file must be correctly modified. If the system fails to start normally .)

☆Create a mysql account

groupadd mysqluseradd -g mysql mysql

☆Dependent package

yum install cmake wget  gcc -y

Cmake: because mysql 5.6 supports cmake installation, we use cmake for installation.

Wget is a linux download tool. below is the mysql source package (downloaded to the current directory)

[root@centos ~]# wget http://101.44.1.118/files/90110000038859AB/nchc.dl.sourceforge.net/project/mysql.mirror/MySQL%205.6.25/mysql-5.6.25.tar.gz

☆Decompress the mysql source code package and go to the decompressed directory.

[root@centos ~]# tar xvf  mysql-5.6.25.tar.gz[root@centos ~]# cd mysql-5.6.25 

☆Configuration

 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

-DCMAKE_INSTALL_PREFIX = point to the mysql installation directory (where to install)

-DMYSQL_DATADIR = mysql DATA DIRECTORY

-DSYSCONFDIR = Mysql configuration file (where to store the configuration file)

The configuration here will go wrong. Please move the nonsense section behind the step to take you to the air ..

          

☆Compile and install (the process is long and patient)

makemake install 

Many people in the group are prone to errors during compilation, and the configuration compilation is not sure whether the operation is successful. although I have explained it below, I still want to mention that there is a $ in linux ?.. After the execution is complete, click "echo $?

If 0 is returned, the preceding command is successfully executed. Any number other than 0 indicates an error.

☆Configure Mysql

★Go to the mysql installation directory

[root@centos ~]#cd /usr/local/mysql

★Set permissions

chown -R mysql .chgrp -R mysql .

★Initialize Database

scripts/mysql_install_db --user=mysql

★Set permissions

chown -R root .chown -R mysql data

★Start Database

bin/mysqld_safe --user=mysql &

Many of my friends will say that they should write a mysql STARTUP script by themselves. mysql already provides the following:

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

In this way, you can start service mysql. server

☆Modify $ PATH

$ PATH? Many people do not know what to do? $ PATH is the variable for executing the file PATH. When we execute a command, [mysql], the System Searches the directory defined by each PATH for executable files named mysql based on the PATH settings. if the directory defined by PATH contains multiple executable files named ls, the files with the same name are first searched and executed!

[Root @ centos ~] # Which mysql

/Usr/bin/which: no mysql in ()

No mysql is found. It is found from so many directories loaded by PATH.

[root@centos ~]#echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

This is the PATH directory defined by the system:

[root@centos ~]#sed -i  '/export PATH/i\\PATH=$PATH:/usr/local/mysql/bin' .bash_profile
[root@centos ~]#source .bash_profile 

Append/usr/local/mysql/bin directly to the back of PATH. I use sed. For Beginners, if you use vi, you can edit it by yourself ..

In this way, you can use mysql

[Root @ centos ~] # Which mysql

/Usr/local/mysql/bin/mysql

3. Nonsense:

For the tutorial, you have to start with nonsense:

The installation of source code is here to compile the configuration and compilation. What is the configuration? How to configure it? Summary. I wrote several thousand lines in detail. In the case of more than 5000 lines, <2.9 Installing MySQL from Source> said how to install...

Configuration is configuration, compilation is compilation. installation is installation. the configuration is cmake, and the compilation is make .. the installation method is make install. make sure that each step is successful. How can I confirm the next step? Check the configuration end prompt, or enter echo $? If 0 is returned, the operation is successful. A non-zero error occurs.

Compilation may not always ensure that 100% is not a problem. The tutorial post is to teach you how to compile and talk about your own experiences. other errors depend on experience and cannot be listed.

If you follow the steps of my operations, the compilation will fail:

Error information:

CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.

CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.

It turns out that it's a problem with C. Why is C? This will increase your knowledge reserves. If you are not sure you want to copy Baidu, take a look at the solution:

yum install gcc -y

Then (execute CMake again). After installation, the error of the second Cxx is not solved, that is, the problem of C ++.

yum install gcc-c++

Run the command again and find that the above error is missing, but there is a new error.

Keywords: no suitable type found Baidu

yum install ncurses-devel

The question cannot be solved, and then we will find that cmakecache.txt is deleted...

Rm-rf CMakeCache.txt

Execute the Cmake command again

 

Compile slowly ..

There are many found, not found

That is to say, some dependencies are found, and some dependencies are not found. If no errors are reported, they are not fatal errors. You can disable some functions in the future (if not installed, why not? Re-configure the compilation and installation, and add the functions you need. You can refer to the official documents for these functions to be installed, or search for them online ..)

Next, compile:

make

Installation:

make install

Confirm that the execution is successful, return to configuring Mysql, and then configure Mysql

Now, what are the errors and questions...

By the way, the following explains how to find configuration items on the Internet:

  

-DCMAKE_INSTALL_PREFIX = point to the mysql installation directory
-DINSTALL_SBINDIR = direct sbin to the executable file directory (prefix/sbin)
-DMYSQL_DATADIR =/var/lib/mysql directs to the mysql data file directory (/var/lib/mysql)
-DSYSCONFDIR =/etc/mysql directs to the mysql configuration file directory (/etc/mysql)
-DINSTALL_PLUGINDIR = lib/mysql/plugin directs to the plug-in directory (prefix/lib/mysql/plugin)
-DINSTALL_MANDIR = share/man points to the man document directory (prefix/share/man)
-Dinstall_1_dir = share: point to the aclocal/mysql. m4 installation directory (prefix/share)
-DINSTALL_LIBDIR = lib/mysql point to the object code library directory (prefix/lib/mysql)
-DINSTALL_INCLUDEDIR = include/mysql points to the header file directory (prefix/include/mysql)
-DINSTALL_INFODIR = share/info: point to the info document storage directory (prefix/share/info)
Prefix is officially recommended as/usr
Storage Engine problems
Type csv, myisam, myisammrg, heap, innobase, archive, blackhole
To enable support for an ENGINE:-DWITH _ <ENGINE> _ STORAGE_ENGINE = 1
For example:
-DWITH_INNOBASE_STORAGE_ENGINE = 1
-DWITH_ARCHIVE_STORAGE_ENGINE = 1
-DWITH_BLACKHOLE_STORAGE_ENGINE = 1
To disable the support of an ENGINE:-DWITHOUT _ <ENGINE> _ STORAGE_ENGINE = 1
For example:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE = 1
-DWITHOUT_FEDERATED_STORAGE_ENGINE = 1
-DWITHOUT_PARTITION_STORAGE_ENGINE = 1
Library Problems
-DWITH_READLINE = 1 enable readline library support (supports editable command lines)
-DWITH_SSL = system enables ssl library support (Secure Sockets Layer)
-DWITH_ZLIB = system enables libz library support (related to zib and gzib)
-DWTIH_LIBWRAP = 0 disable the libwrap Library (implements the universal TCP packaging function and is used by the network service daemon)
-DMYSQL_TCP_PORT = 3306 specify TCP port 3306
-DMYSQL_UNIX_ADDR =/tmp/mysqld. sock specifies the mysql. sock path.
-DENABLED_LOCAL_INFILE = 1 enable local data import support
-DEXTRA_CHARSETS = all enable additional character set types (default value: all)
-DDEFAULT_CHARSET = utf8: Specify the default character set as utf8.
-DDEFAULT_COLLATION = utf8_general_ci: Set the default sorting rule (utf8_general_ci fast/utf8_unicode_ci accurate)
-DWITH_EMBEDDED_SERVER = 1 compile embedded server support
-DMYSQL_USER = mysql-specified mysql user (mysql by default)
-DWITH_DEBUG = 0 Disable debug (disabled by default)
-DENABLE_PROFILING = 0 disable Profiling analysis (enabled by default)
-DWITH_COMMENT = 'string': A descriptive comment on the compiling environment

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.