在macbook上使用Xcode编译mysql 5.6.7-rc源码

2820阅读 0评论2012-10-14 gladness
分类:Mysql/postgreSQL

安装Xcode
安装cmake

解压mysql 5.6.7的源码,在源码目录中
cmake . -G "Xcode"

-- Could NOT find Curses (missing:  CURSES_INCLUDE_PATH) 
CMake Error at cmake/readline.cmake:83 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.
Call Stack (most recent call first):
  cmake/readline.cmake:126 (FIND_CURSES)
  cmake/readline.cmake:193 (MYSQL_USE_BUNDLED_LIBEDIT)
  CMakeLists.txt:324 (MYSQL_CHECK_READLINE)


-- Configuring incomplete, errors occurred!

localhost:mysql-5.6.7-rc avguli$ rm -f CMakeCache.txt 

localhost:mysql-5.6.7-rc avguli$ cmake . -G "Xcode" -DWITH_DEBUG=1 -DCURSES_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/

生成了Xcode的工程文件,在xcode中打开

编译

mysys Group
/Users/avguli/workspace/mysql-5.6.7-rc/mysys/waiting_threads.c
/Users/avguli/workspace/mysql-5.6.7-rc/mysys/waiting_threads.c:297:27: Unused variable 'cycle_stats_lock'
/Users/avguli/workspace/mysql-5.6.7-rc/mysys/waiting_threads.c:297:45: Unused variable 'wait_stats_lock'
/Users/avguli/workspace/mysql-5.6.7-rc/mysys/waiting_threads.c:297:62: Unused variable 'success_stats_lock'

到网上找了半天。有人说修改build settings中的unused variables设置,但发现本来就是no,改成yes也没用,就又改回来。

最后只好尝试修改代码了,把报错的行注释掉。

/* gulei modified

static my_atomic_rwlock_t cycle_stats_lock, wait_stats_lock, success_stats_lock;

*/


再编,这部分编过了。

PhaseScriptExecution "CMake PostBuild Rules" libmysql/MySQL.build/Debug/mysqlclient.build/Script-066B2BDA9973474D845A4E75.sh

    cd /Users/avguli/workspace/mysql-5.6.7-rc

    /bin/sh -c /Users/avguli/workspace/mysql-5.6.7-rc/libmysql/MySQL.build/Debug/mysqlclient.build/Script-066B2BDA9973474D845A4E75.sh


rm /Users/avguli/workspace/mysql-5.6.7-rc/libmysql/Debug/libmysqlclient.a

/usr/bin/libtool -static -o /Users/avguli/workspace/mysql-5.6.7-rc/libmysql/Debug/libmysqlclient.a /Users/avguli/workspace/mysql-5.6.7-rc/libmysql/Debug/libclientlib.a /Users/avguli/workspace/mysql-5.6.7-rc/dbug/Debug/libdbug.a /Users/avguli/workspace/mysql-5.6.7-rc/strings/Debug/libstrings.a /Users/avguli/workspace/mysql-5.6.7-rc/vio/Debug/libvio.a /Users/avguli/workspace/mysql-5.6.7-rc/mysys/Debug/libmysys.a /Users/avguli/workspace/mysql-5.6.7-rc/mysys_ssl/Debug/libmysys_ssl.a /Users/avguli/workspace/mysql-5.6.7-rc/zlib/Debug/libzlib.a /Users/avguli/workspace/mysql-5.6.7-rc/extra/yassl/Debug/libyassl.a /Users/avguli/workspace/mysql-5.6.7-rc/extra/yassl/taocrypt/Debug/libtaocrypt.a

make: /usr/bin/libtool: No such file or directory

make: *** [mysqlclient_buildpart_0] Error 1


找不到libtool

但其实是在xcode的目录里
localhost:mysql-5.6.7-rc avguli$ which libtool
/Applications/Xcode.app/Contents/Developer/usr/bin/libtool

localhost:mysql-5.6.7-rc avguli$ cd /usr/bin/
localhost:bin avguli$ sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/libtool

再编,过了

/Users/avguli/workspace/mysql-5.6.7-rc/sql/mysqld.cc:9474:24: Variable 'all_server_sockets' is not needed and will not be emitted


修改lib_sql.cc

/*

  The following is needed to not cause conflicts when we include mysqld.cc

*/


extern "C"

{

  extern unsigned long max_allowed_packet, net_buffer_length;

}


#include "../sql/mysqld.cc"


/* gulei added */

PSI_socket_info nouse = all_server_sockets[0];



太厉害了,居然编译通过了

project-->edit schema中指定可执行文件,即mysqld

run

121013 22:36:00 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

121013 22:36:00 [ERROR] Can't find messagefile '/usr/local/mysql/share/errmsg.sys'

121013 22:36:00 [Warning] Can't create test file /usr/local/mysql/data/localhost.lower-test

121013 22:36:00 [Warning] Can't create test file /usr/local/mysql/data/localhost.lower-test

/Users/avguli/workspace/mysql-5.6.7-rc/sql/Debug/mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)

121013 22:36:00 [ERROR] Aborting


121013 22:36:00 [Note] Binlog end

121013 22:36:00 [Note] 


这看起来已经是编译通过了,只是mysqld启动时的参数需要设置了。

在菜单project-》edit schema中,在arguments中增加两行参数
--basedir=/Users/avguli/workspace/mysql-5.6.7-rc/sql
--datadir=/Users/avguli/workspace/mysql-5.6.7-rc/sql/data

再运行

121014 14:19:22 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

121014 14:19:22 [Warning] Setting lower_case_table_names=2 because file system for /Users/avguli/workspace/mysql-5.6.7-rc/sql/data/ is case insensitive

121014 14:19:22 [Note] Plugin 'FEDERATED' is disabled.

/Users/avguli/workspace/mysql-5.6.7-rc/sql/Debug/mysqld: Table 'mysql.plugin' doesn't exist

121014 14:19:22 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

121014 14:19:22 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!

121014 14:19:22 InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!

121014 14:19:22 InnoDB: The InnoDB memory heap is disabled

121014 14:19:22 InnoDB: Mutexes and rw_locks use GCC atomic builtins

121014 14:19:22 InnoDB: Compressed tables use zlib 1.2.3

121014 14:19:22 InnoDB: CPU supports crc32 instructions

121014 14:19:22 InnoDB: Initializing buffer pool, size = 128.0M

121014 14:19:22 InnoDB: Completed initialization of buffer pool

InnoDB: The first specified data file ./ibdata1 did not exist:

InnoDB: a new database to be created!

121014 14:19:22 InnoDB: Setting file ./ibdata1 size to 12 MB

InnoDB: Database physically writes the file full: wait...

121014 14:19:22 InnoDB: Log file ./ib_logfile0 did not exist: new to be created

InnoDB: Setting log file ./ib_logfile0 size to 5 MB

InnoDB: Database physically writes the file full: wait...

121014 14:19:22 InnoDB: Log file ./ib_logfile1 did not exist: new to be created

InnoDB: Setting log file ./ib_logfile1 size to 5 MB

InnoDB: Database physically writes the file full: wait...

121014 14:19:22 InnoDB: Doublewrite buffer not found: creating new

121014 14:19:22 InnoDB: Doublewrite buffer created

121014 14:19:22 InnoDB: 128 rollback segment(s) are active.

121014 14:19:22 [Warning] InnoDB: Creating foreign key constraint system tables.


121014 14:19:22 [Note] InnoDB: Foreign key constraint system tables created


121014 14:19:22 [Note] InnoDB: Creating tablespace and datafile system tables.


121014 14:19:22 [Note] InnoDB: Tablespace and datafile system tables created


121014 14:19:22 InnoDB: Waiting for the background threads to start

121014 14:19:22 InnoDB: 1.2.7 started; log sequence number 0

121014 14:19:22 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 18901b9e-15c7-11e2-8b89-2e9357fce896.

121014 14:19:22 [Note] Server hostname (bind-address): '*'; port: 3306

121014 14:19:22 [Note] IPv6 is available.

121014 14:19:22 [Note]   - '::' resolves to '::';

121014 14:19:22 [Note] Server socket created on IP: '::'.

121014 14:19:22 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist


这回是系统表没有初始化造成的了

localhost:scripts avguli$ pwd
/Users/avguli/workspace/mysql-5.6.7-rc/scripts
localhost:scripts avguli$ cd ..
localhost:mysql-5.6.7-rc avguli$ cd scripts/
localhost:scripts avguli$ ls -l mysql_install_db
-rw-r--r--  1 avguli  staff  14803 10 13 20:10 mysql_install_db
localhost:scripts avguli$ pwd
/Users/avguli/workspace/mysql-5.6.7-rc/scripts
localhost:scripts avguli$ ls -l mysql_install_db
-rw-r--r--  1 avguli  staff  14803 10 13 20:10 mysql_install_db
localhost:scripts avguli$ chmod u+x mysql_install_db
localhost:scripts avguli$ ./mysql_install_db --datadir=../sql/data

FATAL ERROR: Could not find ./bin/my_print_defaults

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

localhost:scripts avguli$ find . -name my_print_defaults
localhost:scripts avguli$ pwd
/Users/avguli/workspace/mysql-5.6.7-rc/scripts
localhost:scripts avguli$ cd ..
localhost:mysql-5.6.7-rc avguli$ find . -name my_print_defaults
./extra/Debug/my_print_defaults
localhost:mysql-5.6.7-rc avguli$ ./scripts/mysql_install_db --basedir=./sql --datadir=./sql/data

FATAL ERROR: Could not find my_print_defaults

The following directories were searched:

    ./sql/bin
    ./sql/extra

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

看来还是要重新配置重启编译,再make install了

因为不想装在/usr/local下面

重新来过

cmake . -G "Xcode" -DWITH_DEBUG=1 -DCURSES_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/ -DCMAKE_INSTALL_PREFIX=/Users/avguli/workspace/bin/mysql5.6.7 -DMYSQL_DATADIR=/Users/avguli/workspace/bin/mysql5.6.7/data

air的风扇又在呜呜叫了。

这次很顺利。

用Xcode打开

编译,如前两次代码修改。顺序通过。

project-》edit schema指定可执行文件为mysqld

localhost:mysql-5.6.7-rc avguli$ pwd
/Users/avguli/workspace/source/mysql-5.6.7-rc
localhost:mysql-5.6.7-rc avguli$ make install
make: *** No rule to make target `install'.  Stop.
localhost:mysql-5.6.7-rc avguli$ make
make: *** No targets specified and no makefile found.  Stop.

Xcode编译的似乎无法make install,只好自己复制文件了。

localhost:mysql-5.6.7-rc avguli$ cp sql/debug/mysqld ../../bin/mysql5.6.7/bin/
cp client/Debug/mysql* ../../bin/mysql5.6.7/bin/
把share目录和scripts目录也都复制过去

localhost:mysql5.6.7 avguli$ chmod u+x /Users/avguli/workspace/bin/mysql5.6.7/scripts/*

localhost:workspace avguli$ cd source/mysql-5.6.7-rc/
localhost:mysql-5.6.7-rc avguli$ find . -name my_print_defaults
./extra/Debug/my_print_defaults
localhost:mysql-5.6.7-rc avguli$ cd extra/Debug/
localhost:Debug avguli$ ls
comp_err my_print_defaults perror resolve_stack_dump
innochecksum mysql_waitpid replace resolveip
localhost:Debug avguli$ pwd
/Users/avguli/workspace/source/mysql-5.6.7-rc/extra/Debug
localhost:Debug avguli$ ls -l
total 56440
-rwxr-xr-x  1 avguli  staff  3642788 10 14 15:09 comp_err
-rwxr-xr-x  1 avguli  staff  3614028 10 14 15:09 innochecksum
-rwxr-xr-x  1 avguli  staff  3601252 10 14 15:09 my_print_defaults
-rwxr-xr-x  1 avguli  staff  3596604 10 14 15:13 mysql_waitpid
-rwxr-xr-x  1 avguli  staff  3697604 10 14 15:09 perror
-rwxr-xr-x  1 avguli  staff  3524104 10 14 15:09 replace
-rwxr-xr-x  1 avguli  staff  3602148 10 14 15:09 resolve_stack_dump
-rwxr-xr-x  1 avguli  staff  3596968 10 14 15:09 resolveip
localhost:Debug avguli$ cp * /Users/avguli/workspace/bin/mysql5.6.7/bin/


localhost:mysql5.6.7 avguli$ find ../../source/mysql-5.6.7-rc/ -name fill_help_tables.sql
../../source/mysql-5.6.7-rc//scripts/fill_help_tables.sql
localhost:mysql5.6.7 avguli$ cp ../../source/mysql-5.6.7-rc//scripts/*sql share/
localhost:mysql5.6.7 avguli$ pwd
/Users/avguli/workspace/bin/mysql5.6.7

localhost:mysql5.6.7 avguli$ ./scripts/mysql_install_db
Installing MySQL system tables...
121014 15:58:36 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
121014 15:58:36 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
121014 15:58:36 InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!
121014 15:58:36 InnoDB: The InnoDB memory heap is disabled
121014 15:58:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
121014 15:58:36 InnoDB: Compressed tables use zlib 1.2.3
121014 15:58:36 InnoDB: CPU supports crc32 instructions
121014 15:58:36 InnoDB: Initializing buffer pool, size = 128.0M
121014 15:58:36 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
121014 15:58:36 InnoDB: Setting file ./ibdata1 size to 12 MB
InnoDB: Database physically writes the file full: wait...
121014 15:58:36 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
121014 15:58:36 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
121014 15:58:36 InnoDB: Doublewrite buffer not found: creating new
121014 15:58:36 InnoDB: Doublewrite buffer created
121014 15:58:37 InnoDB: 128 rollback segment(s) are active.
121014 15:58:37 [Warning] InnoDB: Creating foreign key constraint system tables.

121014 15:58:37 [Note] InnoDB: Foreign key constraint system tables created

121014 15:58:37 [Note] InnoDB: Creating tablespace and datafile system tables.

121014 15:58:37 [Note] InnoDB: Tablespace and datafile system tables created

121014 15:58:37 InnoDB: Waiting for the background threads to start
121014 15:58:37 InnoDB: 1.2.7 started; log sequence number 0
121014 15:58:38 [Note] Binlog end
121014 15:58:38 InnoDB: FTS optimize thread exiting.
121014 15:58:38 InnoDB: Starting shutdown...
121014 15:58:38 InnoDB: Shutdown completed; log sequence number 1629432
OK
Filling help tables...
121014 15:58:38 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
121014 15:58:38 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
121014 15:58:38 InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!
121014 15:58:38 InnoDB: The InnoDB memory heap is disabled
121014 15:58:38 InnoDB: Mutexes and rw_locks use GCC atomic builtins
121014 15:58:38 InnoDB: Compressed tables use zlib 1.2.3
121014 15:58:38 InnoDB: CPU supports crc32 instructions
121014 15:58:38 InnoDB: Initializing buffer pool, size = 128.0M
121014 15:58:38 InnoDB: Completed initialization of buffer pool
121014 15:58:38 InnoDB: highest supported file format is Barracuda.
121014 15:58:40 InnoDB: 128 rollback segment(s) are active.
121014 15:58:40 InnoDB: Waiting for the background threads to start
121014 15:58:40 InnoDB: 1.2.7 started; log sequence number 1629432
121014 15:58:40 [Note] Binlog end
121014 15:58:40 InnoDB: FTS optimize thread exiting.
121014 15:58:40 InnoDB: Starting shutdown...
121014 15:58:41 InnoDB: Shutdown completed; log sequence number 1629442
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

成功

写个配置文件
localhost:data avguli$ pwd
/Users/avguli/workspace/bin/mysql5.6.7/data
localhost:data avguli$ more my.cnf 
[mysqld]
innodb_file_per_table
socket = /Users/avguli/workspace/bin/mysql5.6.7/data/mysql.sock
port = 5670


在Xcode的project-》edit schema中的arguments中增加一行
--defaults-file=/Users/avguli/workspace/bin/mysql5.6.7/data/my.cnf

在Xcode中run

mysqld成功启动

可以用Xcode跟踪mysql源码了,Yeah
上一篇:pt-online-schema-change使用实例
下一篇:写mysql技术文章或者ppt时以漂亮格式记录案例的方法