天嵌 ARM开发社区

 找回密码
 注册
查看: 2834|回复: 0

apache+php+mysql的嵌入式移植----2

[复制链接]
流浪记 发表于 2013-8-26 16:09:53 | 显示全部楼层 |阅读模式
本帖最后由 流浪记 于 2013-8-29 18:23 编辑

Mysql的嵌入式移植(mysql-5.1.69)
编译mysql也需要编译两个版本,一个是基于本机的,一个是基于ARM的。
我这里将基于本机的解压到/home/jason/PC/下,将基于ARM的解压到/home/jason/arm下。
编译本机版本的mysql
# cd  /home/jason/PC/mysql-5.1.69
# ./configure
# make
这里仍然不需要make install,因为我们只需要用到本机编译后的gen_lex_hash文件。

下面编译arm版本的mysql
这里要用到ncurses库,所以先安装这个库,ncurses-5.9.tar.gz并解压
#  cd  /ncurses-5.9
#  ./configure  --enable-static        这里我用的是默认安装目录。
#  make
#  make install
开始编译基于arm的 mysql
# cd  /home/jason/arm/mysql-5.1.69
#sudo gedit configure 打开配置文件,修改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部分,要全部改掉。
12. #CC=arm-linux-gcc ./configure --host=arm-linux –-enable-static --with-named-curses-libs=/usr/local/ncurse/lib/libncurses.a  --localstatedir=/var/lib/mysql --prefix=/usr/local/mysql --without-debug --without-docs --without-man --without-bench --with-charset=gb2312 --with-extra-charsets=ascii,latin1,utf8
13 . 修改/mysql-5.1.69/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的开头处,而应该加在用这个宏的前面一句。
复制PC版本的gen_lex_hash文件到arm版本的对应路径处
#  cp  /mysql-5.1.51-pc/sql/gen_lex_hash  sql/
#  touch  –m  sql/gen_lex_hash
#  cp  /mysql-5.1.51-pc/sql/lex_hash.h  sql/
#  touch  –m  sql/lex_hash.h
#  make
#  mak  install
将/usr/local/下的mysql文件夹移植到开发板相同目录下,即/usr/local/.
将mysql源码(基于arm的)中的/mysql-5.1.69/support-files/my-medium.cnf文件拷贝到开发板的/etc/目录下,并改名字为my.conf
下面说的都是在开发板里面执行的,即串口终端,什么意思自己去了解下,需要用到minicom。
运行mysql_install_db
  # cd  /usr/local/mysql/bin
  # 运行 ./mysql_install_db  -u  root
结果出现了如下错误:Neither host 'EmbedSky' nor 'localhost' could be looked up with /usr/local/mysql/bin/resolveip Please configure the 'hostname' command to return a correct hostname. If you want to solve this at a later stage, restart this script with the --force option 这主要的原因是开发板环境中的hostname是EmbedSky,所以mysql自动认为可能在该操作系统中的运行会不兼容.
解决办法:# ./mysql_install_db --user=root --force --basedir=/usr/local/mysql --datadir=/var/lib/mysql
.创建mysqld.pid文件(不知道这步是不是必须,但我做了)
在/var/run目录下穿件mysqld文件夹  #  mydir  /usr/run/mysqld
并在该文件夹创建文件mysqld.pid  # touch /var/run/mysqld/mysqld.pid
拷贝mysql-5.1.69/support-files/mysql.server 文件到开发板的/etc/init.d/目录下并改名为mysqld,修改这个mysqld文件:
添加下列几项的值
Basedir =/usr/local/mysql
Datadir =/var/lib/mysql
pid-file=/var/run/mysqld/mysqld.pid
修改完后要给mysqld文件以足够的权限  #chmod  777 mysqld
21 .在开发板上开启mysql服务
# cd  /etc/init.d
# ./mysqld  start
结果出错:Starting MySQL... ERROR! Manager of pid-file quit without updating file.
到开发板目录/var/lib/mysql下查阅错误日志文件EmbedSky.err,从中看到下面的记录:
150713 21:04:49 [ERROR] Fatal error: Can't change to run as user 'mysql' ;  Please check that the user exists!
因此需要采用如下方法解决该问题:
#  cd /var/lib/mysql
#  ls –la可以看到里面的属性中没有mysql,于是使用下面的命令:
# adduser mysql
# chown mysql:mysql -R /var/lib/mysql
然后开启mysql服务,还是出现了ERROR! Manager of pid-file quit without updating file. 又查看EmbedSky.err日志,其中多了一条:
150714  2:48:04 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use。
这似乎是端口被占用了,当然你不一定会碰到这个问题,不管出什么问题,查看错误日志来解决。
# cd  /etc/init.d
# ./mysqld  start 启动mysql服务。
22. 设置软连接使mysql,  mysqldump,  mysqladmin这三个命令能在开发板的shell中直接运行。
# ln -s /usr/local/mysql/bin/mysql  /usr/bin
# ln -s /usr/local/mysql/bin/mysqldump  /usr/bin
# ln -s /usr/local/mysql/bin/mysqladmin  /usr/bin
23.修改密码方法:
  # mysqladmin -u  root   password   hahaha(hahaha即为你要改的密码)
这样就可以用这个密码进入mysql操作界面了
进入mysql服务界面的方法:
# mysql -u root -p
Enter passwd :这里输入密码就可以进入mysql服务界面
Mysql> (这是进入mysql服务界面的标志)
启动mysql的过程中可能会出现问题:
ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)
解决方法:#  cd  /etc/init.d/
          #  ./mysqld  stop          # cd  /usr/local/mysql/bin
         # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
解决了这个问题之后可以再进入mysql服务
# mysql  -u  root -p
Enter passwd : 输入密码
Mysql>



移植后感:整个apache+php+mysql的移植花了我真的有3个星期,当然对于我这个刚接触linux的人来说这个时间还是可以的,哈哈,小小的得意一下。当然过程肯定不会一帆风顺,无论移植这里面的哪一个,都遇到了太多的问题,解决了一个问题,又出现一个新的问题,出现问题当然去找度娘了,有些问题很多人碰到,所以会有很多解决方法供我们参考,有些方法不一定适合自己,只有再尝试了很多方法之后才能找到真正能解决问题的那个。不过有些问题在度娘里面可能找不到答案,那就问问google咯,还有一些大家用的比较少的搜索引擎,比如360,有道,必应,Jlike时刻等等都可以尝试下,也许就能找到能解决你问题的方法。
花了差不多一整天的时间来整理这个,一来是以后可能会再次移植,二来是想认真写个文档,供别的朋友参考,毕竟这个是集结了很多网友的移植经验,当我们成功之后再将自己成功的经验供别的网友参考。
有问题的朋友可以加我QQ,374075382,输入验证我的名字:邓林杰.互相交流,互相学习。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-4-18 10:58 , Processed in 1.031257 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表