一:编译ARM平台的mysql
1.安装交叉编译器,这里用的是4.3.2
检测交叉编译环境方法:arm-linux-gcc –v
root@ubuntu:/#arm-linux-gcc -v
Using built-inspecs.
Target:arm-none-linux-gnueabi
Configured with:/scratch/julian/lite-respin/linux/src/gcc-4.3/configure--build=i686-pc-linux-gnu --host=i686-pc-linux-gnu--target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap--disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld--enable-languages=c,c++ --enable-shared --enable-symvers=gnu--enable- __cxa_atexit --with-pkgversion='Sourcery G++ Lite 2008q3-72'--with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls--prefix=/opt/codesourcery -- with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc--with-build-sysroot=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/libc--with- gmp=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr--with-mpfr=/scratch/julian/lite-respin/linux/obj/host-libs- 2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr--disable-libgomp --enable-poison-system-directories--with-build-time-tools=/scratch/julian/lite- respin/linux/install/arm-none-linux-gnueabi/bin--with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin
Thread model:posix
gcc version4.3.2 (Sourcery G++ Lite 2008q3-72)
2.下载mysql5.1.73
mysql-5.1.73.tar.gz下载地址:
http://download.csdn.net/detail/liangzhuangdongtou/9526994
3. 编译PC版本的mysql备用
a) 解压mysql-5.1.73到/opt/mysql-5.1.73: tar zxvf mysql-5.1.73.tar.gz
b) cd mysql-5.1.73
c) ./configure -prefix=/usr/local/mysql
d) make 注意,这里无需运行make install,以为主要是为了用pc版本里的gen_lex_hash库。(注意一定要先make后,再去修改文件夹名称)
e) 将文件夹mysql-5.1.73改名为mysql-5.1.73-pc备用。(将gen_lex_hash单独备份保存一下)
4) 编译arm版本的ncurses
a) 下载ncurses-5.6.tar.gz
ncurese-5.6.tar.gz下载地址:
http://download.csdn.net/detail/liangzhuangdongtou/9563468
b) 解压到/opt/中:tar zxvf ncurses-5.6.tar.gz
c) cd ncurses-5.6
d) ./configure –host=arm-linux -prefix=/usr/local/ncurse –enable-static
e) make
f) make install之所以安装这个,是因为对mysql的交叉编译过程需要该库的支持
(此步在用sudomake install时出错,原因是环境变量和原来不同了,解决办法:sudo -i;makeinstall
5) 编译arm版本的mysql
a) tar zxvf mysql-5.1.73.tar.gz
b) cd mysql-5.1.73
c) 修改配置文件:打开configure,可以使用geditconfigure:
if test "$cross_compiling" =yes; then
{ { $as_echo "$as_me:$LINENO:error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in\`$ac_pwd':" >&2;}
{ { $as_echo "$as_me:$LINENO:error: cannot run test program while cross
compiling See \`config.log' for moredetails." >&5
$as_echo "$as_me: error: cannotrun test program while cross compiling See \`config.log' for moredetails." >&2;}
{(exit 1); exit 1; }; }; }
Else
将这些代码改为(这样的代码有4部分,要全部改掉):
if test"$cross_compiling" = yes; then
echo "skip !!!"
#{ { $as_echo "$as_me:$LINENO:error: in \`$ac_pwd':" >&5 #$as_echo "$as_me: error: in\`$ac_pwd':" >&2;}
#{ { $as_echo "$as_me:$LINENO:error: cannot run test program while cross compiling See \`config.log' for moredetails." >&5
#$as_echo "$as_me: error: cannotrun test program while cross compiling See \`config.log' for moredetails." >&2;}
#{ (exit 1); exit 1; }; }; }
Else
d) 配置,直接套用了人家的配置方式:
./configure--host=arm-linux --enable-static --with-named-curses-libs=/usr/local/ncurse/lib/libncurses.a--prefix=/usr/local/mysql --without-debug --without-docs --without-man--without-bench --with-charset=gb2312 --with-extra-charsets=ascii,latin1,utf8
e) 修改opt/mysql-5.1.73/sql/sql_parse.cc:在5741行之前添加#define STACK_DIRECTION 1
如果不修改该语句,则会出现如下错误:sql_parse.cc:5646:21:operator '<' has no left operand,原因是宏变量STACK_DIRECTION没有定义初值,arm中定义STACK_DIRECTION为1。
注意:这里的“#define STACK_DIRECTION 1”一句,不能随便加在sql_parse.cc的开头处,而应该根据出错信息的提示添加在相应的行上,我所遇到的行号和别人文档上所遇到的行号并不相同。
f) 复制PC版本的gen_lex_hash文件到当前文件夹:
cp /opt/mysql-5.1.73-pc/sql/gen_lex_hash sql/
touch –msql/gen_lex_hash
cp /opt/mysql-5.1.73-pc/sql/ lex_hash.h sql/
touch –m sql/lex_hash.h
否则会出现错误:
make[2]: Leavingdirectory `/opt/mysql-5.5.3-m3/sql' ./gen_lex_hash > lex_hash.h-t
/bin/sh:./gen_lex_hash: cannot execute binary file 因为arm版的无法在pc上运行。
注意:别人的文档上说只要拷贝gen_lex_hash即可,但我试了好多次,都仍然会出现上面的报错信息,把lex_hash.h也拷贝过来后,就不再报错了。另外,touch一定要做,原因就是让编译器不要再编译覆盖拷贝过来的文件了。
g) Make
h) Make install
**************************************************************************
二:移植mysql到ARM平台
1、拷贝交叉编译好的文件夹到板子上对应的路径下,/usr/local/mysql
2、将/usr/local/mysql/share/mysql/mysql.server拷贝到/etc/init.d/mysql.server
cp /usr/local/mysql/share/mysql/mysql.server/etc/init.d/mysql.server
3、添加配置文件
gedit /etc/my.conf
内容如下:
[mysqld]
datadir=/usr/local/mysql/mysql_data
socket=/tmp/mysql.sock
user=root
#Default to using old password format for compatibility with mysql3.x
#clients (those using the mysqlclient10 compatibility package).
old_passwords=1
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/lib/mysql/camelshoko.pid
3.版本测试
#/usr/local/mysql/bin/mysql -V
./mysql Ver 14.14 Distrib5.1.73, for unknown-linux-gnu (arm) using EditLine wrapper
4.安装数据库
#/usr/local/mysql/bin/mysql_install_db –u root –force
5.启动MySQL服务
# /etc/rc.d/init.d/mysql.server start
Starting MySQL… SUCCESS!
6、MySQL测试
#/usr/local/mysql/bin/mysql –uroot -p
7、MySQL设置为开机自动启动
\etc\rc.d文件夹下rcS中添加:其中mysql-arm是移植到arm平台的路径
chmod -R 777 /usr/local/mysql-arm
export PATH=/usr/local/mysql-arm:$PATH
export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql-arm:$LD_LIBRARY_PATH
/usr/local/mysql-arm/bin/mysql.server start &