Today formally began a long road, I intend to spend the last few years to brush mysql5.5 source code, because the books at hand are basically based on mysql5.5, so there is no 5.7 version of the code, not to mention I am more concerned about the basic kernel. Therefore, there is no special indication, then generally refers to the mysql5.5 version. Work reasons do not go deep to understand MySQL, since want to play the technology, the technical challenges of the work did not study the MySQL kernel so direct, so decided to spend spare time to engage in some technical work, on the one hand can let their own technology in-depth reserves, on the other hand also let oneself in the work from the technology to obtain a point of accomplishment.
Choose Mac Platform because of the simple, the Windows platform I also compiled successfully, but the Internet and around the data are basically Linux-based, and MySQL this server program is obviously more and Linux affinity, so decided to use the Mac platform to play the MySQL kernel. OS x is certainly not Linux, but basically generic.
My Mac OS version is 10.11.1 (15B42), and Xcode is 7.3.1.
I. Things to install before compiling
Of course it has to be xcode, which can be downloaded for free on the App store.
Next, is CMake, strongly recommended, or must use the command line version of the CMake, so do not go to the official website to download the UI version of CMake, should go to git download,:
Https://github.com/Kitware/CMake
After downloading, execute the Third Kind command in the directory--configure,make and sudo make install. At this point, the required compilation tools are ready.
Second, download the MySQL source code
Also download the MySQL source code in git:
Https://github.com/mysql/mysql-server
Note Select the 5.5 version in the branch location.
Third, compile MySQL
First unzip out the MySQL source code to its own new directory, the following assumption that the source code in its own built MySQL directory, and then, the new directory MYSQL/BLD,CD into Mysql/bld, execute the following command:
CMake. –G "Xcode" –dcmake_install_prefix=mysql/bld/install
Among them,.. Represents the location of the MySQL source code,-G "Xcode" means to generate the Xcode project file, so that you can compile and debug Mysql,-dcmake_install_prefix in Xcode, which means that MySQL should be installed where the absolute path is recommended, I have not tried to use the relative path, and, the installation location should not be placed in usr/local this place, after all, this compiled MySQL version is not to learn MySQL application, but to toss, so, or distinguish between put as good.
After executing the command, there will be a xcodeprj file in the Mysql/bld, double-click to open, see Xcode mysql project file, in the upper left corner select All_build:
Then click on the next triangle to compile the execution button, will be ready to compile.
At this time, if you go to the Mysql/bld/install directory, you can see the familiar MySQL program directory:
Where my.cnf is I manually created, because MySQL will default to choose some fixed path to find my.cnf, just said, this MySQL is for me to toss, so can not disturb the normal use of MySQL, gu to write a my.cnf, I wrote in this directory, the content is mainly using port 33060, and the number According to the documents put in Mysql/bld/install/data:
[Mysqld]
Datadir=mysql/bld/install/data
Socket=mysql/bld/install/mysql.sock
port=33060
Note that the directory should write absolute paths!
Four, commissioning mSQL
At first MySQL has no content, including database data, username and password, so some initialization work is required:
First, turn off the normal running MySQL:
This is my normal use of MySQL, it is best to close.
Open the generated Xcode project and select Mysqld in the upper-left corner:
Then choose menu Product/scheme/edit Scheme, pop Up the dialog box, choose Run on the left, enter on the right
That is, the--defaults-file=my.cnf file path,--basedir=install path.
Next is to click on the top left corner of the triangular compiler execution key to run the mysqld process, that is, you can use Xcode to debug MySQL.
By the way, MySQL does not have a username and password at first, and it does not generate data for the recent database (such as system,scheme_information, etc.) and can be mysql/bld/install/ Use the Mysqladmin command in the bin to set the user name password:
Mysqladmin-uroot--port 33060-p Password 123456
Then in the mysql/bld/install/scripts, with
Mysql_install_db-uroot-p 123456--port 33060
Initializes the MySQL system database data. Since then, MySQL has basically set up a debugging environment on a Mac.
MySQL compilation and debugging on a Mac