Chinaunix首页 | 论坛 | 博客
  • 博客访问: 252512
  • 博文数量: 65
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-29 21:49
个人简介

Flowers_World

文章分类

全部博文(65)

文章存档

2017年(7)

2016年(38)

2015年(14)

2014年(6)

我的朋友

分类: 嵌入式

2014-12-08 20:53:24

参考博文:http://www.cnblogs.com/Charles-Zhang-Blog/p/3529980.html
一:开发环境

    主机开发环境:                                                                     VMWARE 下安装的 UBUNTU 10.04
     gcc编译器:                                                                            ubuntu自带的,version 4.4.3
    开发板:                                                                                   
   交叉编译器                                                                              arm-linux-gcc version 4.4.3
二:编译过程

1) 下载mysql5.1.51: 

   

2) 安装编译器:用的是4.4.3的交叉编译器。gcc之类的都是ubuntu10.04自带的。

3) 编译PC版本的mysql备用 
    a) 解压mysql-5.1.51到/opt/mysql-5.1.51: tar zxvf mysql-5.1.51.tar.gz 

    b) cd mysql-5.1.51 
    c) ./configure --prefix=/usr/local/mysql 

    d) make 注意,这里无需运行make install,以为主要是为了用pc版本里的gen_lex_hash库。(注意一定要先make后,再去修改文件夹名称) 

    e) 将文件夹mysql-5.1.51改名为mysql-5.1.51-pc备用。(将gen_lex_hash单独备份保存一下) 
    f) 文档上说这里会出错,但我在编译的过程中没有碰到,唯一的问题是编译了arm版本的,重新通过改文件夹的名字回头编译pc版本的时候会报错。 


4) 编译arm版本的ncurses 
    a) 下载ncurses-5.6.tar.gz

    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的交叉编译过程需要该库的支持

      (此步在用sudo make install时出错,原因是环境变量和原来不同了,解决办法:sudo -i;make install) 

 

5) 编译arm版本的mysql 
    a) tar zxvf mysql-5.1.51.tar.gz 

    b) cd mysql-5.1.51 
    c) 修改配置文件:打开configure,可以使用gedit configure 分别在第26453行、 48175行、 48282行、 48485行附近有类似代码: 
        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 more details." >&5 

        $as_echo "$as_me: error: cannot run test program while cross compiling See \`config.log' for more details." >&2;} 
        { (exit 1); exit 1; }; }; } 

        Else 

        将这些代码改为: 
        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 more details." >&5 
        #$as_echo "$as_me: error: cannot run test program while cross compiling See \`config.log' for more details." >&2;} 
        #{ (exit 1); exit 1; }; }; } 

        Else 

        一定注意,这样的代码有4部分,要全部改掉。 
    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.51/sql/sql_parse.cc:在5646行之前添加#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.51-pc/sql/gen_lex_hash sql/ 

       touch –m sql/gen_lex_hash  
       cp  /opt/mysql-5.1.51-pc/sql/ lex_hash.h sql/ 

       touch –m sql/ lex_hash.h 
       否则会出现错误: 
       make[2]: Leaving directory `/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上运行。

  g) Make 
      make过程中出现的不其它能执行二进制错误需要将PC版本中对应路径下的文件拷贝过来;  
  h
) Make install 
三:移植到开发板
a) 拷贝pc的/usr/local/mysql到开发板的相同目录 ;
b) 到源码中拷贝配置文件模版

 
cp /opt/mysql-5.1.51/support-files/my-medium.cnf到开发板的 /etc/my.cnf 
     屏蔽掉my.cnf中如下两条内容#log-bin=mysql-bin
                                                 #binlog_format=mixed
c) 初始化数据库
   
#cd /usr/local/mysql/bin
     #./mysql_install_db  --user=root  --force  --basedir=/usr/local/mysql  --datadir=/tmp/var(我修改了datadir的路径) 
    初始化结束后会在/tmp/var下生成mysql和test两个数据库目录。
d) 启动MySQL
   
#./mysqld_safe  --user=root  &

e) 设置密码
   
#./mysqladmin  -u  root  password  123456
f) 登录MySQL
     
#./mysql  -u root  -p
     输入密码后就进入到了MySQL

四:测试
进入到MySQL后可以通过如下命令进行测试:
  #use test;//使用test数据库
  #create table t1(name char(10));//创建表
  #insert into t1 values("sun");//插入
  #select * from t1;//查询

阅读(1374) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~