環境準備
1.下載mysql源代碼:http://dev.mysql.com/downloads/mysql/#downloads 這裏最新的版本是mysql-5.5.25a
如下:
2.安裝CMake
下載地址:http://www.cmake.org/cmake/resources/software.html 編譯器, 記得Linux下的 make麼, 沒錯這個就是他哥,進階版。
3.安裝GNUWin32 Bison
下載地址爲:http://gnuwin32.sourceforge.net/packages/bison.htm, 同樣安裝路徑最好爲英文,並且不要有空格。安裝後將bin路徑添加到系統環境變量。
編譯
進入mysql的根目錄下,輸入cmake . -G "Visual Studio 9 2008",正常的話會有XXX done什麼的
成功的話會有MySQL.sln和一大堆.vcproj文件,打開MySQL.sln,就可以看到整個解決方案
在編譯之前,建議打開sql/sql_locale.cc文件,將其用utf-8格式再保存一遍,不然編譯過程當中會有大量錯誤。
應該就可以編譯成功。
到sql/debug 下執行
mysqld-debug --debug –-standalone
應該會出現錯誤,提示你mysqld.cc中的某個斷言有問題,把那段註解掉重新編譯。
編譯完以後繼續
mysqld-debug --debug –-standalone
發現還是起不來mysqld的進程。
查看log文件
mysqld.exe: Table 'mysql.plugin' doesn't exist
120414 11:34:08 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120414 11:34:08 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
120414 11:34:08 InnoDB: The InnoDB memory heap is disabled
120414 11:34:08 InnoDB: Mutexes and rw_locks use Windows interlocked functions
120414 11:34:08 InnoDB: Compressed tables use zlib 1.2.3
120414 11:34:08 InnoDB: Initializing buffer pool, size = 128.0M
120414 11:34:08 InnoDB: Completed initialization of buffer pool
120414 11:34:08 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
120414 11:34:08 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
120414 11:34:09 InnoDB: Waiting for the background threads to start
120414 11:34:10 InnoDB: 1.1.8 started; log sequence number 1595675
120414 11:34:10 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
意思是mysl下的表沒有建立,很奇怪這個不知道是什麼原因,我是到別的地方拷貝了mysql下的文件放到sql/data/mysql下
如果沒有什麼意外
執行
mysqld-debug --debug –-standalone
就可以建立啓動mysqld進程了。
使用vs2008進行調試
測試---》附加到進程
選擇mysqld
定位到 \client\Debug,執行命令“mysql -u root -p”,進入mysql客戶端,
在這邊下斷點:
在mysql 客戶端下:
show authors;
就可以進入斷點進行調試: