1. 源码下载
下载MySQL最新5.1版本的源代码,这里下载的是mysql-5.1.73.tar.gz版本。
http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/
2. 交叉编译与移植
网上有一份比较详细的mysql-5.1.51版本的MySQL数据库移植手册《Ubuntu下编译ARM平台QtEmbedded的MySQL和MySQL插件.pdf》,5.1.73变化不大,完全可以参考这份文档进行移植。里面的内容都是正确的,但有几个地方不一样:
1)/bin/bash: line 1: ../scripts/comp_sql: cannot execute binary file
在文档中comp_sql没有提到,这里只需要进入这个目录下使用gcc命令重新编译一个x86的版本就可以了:
gcc -o comp_sql comp_sql.c
2)后面还有一个程序comp_err,直接从x86编译的目录下拷贝过来就可以了。注意可执行文件生成的时间。
3)make install注意
直接make install提示错误,sudo make install还是错误。需要先sudo -s,使用root用户make install就不会有错误了。
这里使用的配置命令为:
./configure --host=arm-linux --enable-static
--with-named-curses-libs=/usr/local/arm/ncurse/lib/libncurses.a
--prefix=/usr/local/arm/mysql --without-debug --without-docs
--without-man
--without-bench
--with-charset=gb2312
--with-extra-charsets=ascii,latin1,utf8
make install命令会将程序安装到/usr/local/arm/mysql目录下,将这个目录拷贝到i.MX6开发板中,注意:开发板目录必须和这里的目录完全一致。
3. 使用MySQL数据库
进入开发板MySQL数据库bin目录:
cd /usr/local/arm/mysql/bin/
执行安装命令
./mysql_install_db --user=root
将MySQL自带的默认配置文件拷贝到etc目录下:
cp /usr/local/arm/mysql/share/mysql/my-large.cnf /etc/my.cnf
cp /usr/local/arm/mysql/share/mysql/mysql.server /etc/mysql.server
查看当前MySQL运行状态:
/etc/mysql.server status
启动MySQL数据库
/etc/mysql.server start
错误解决:
1)第一次运行可能会有如下错误:
root@viny /etc$ ./mysql.server start
Starting MySQL. ERROR! Manager of pid-file quit without updating file.
解决方法:第一次运行需要安装一下数据库的数据文件保存路径
./mysql_install_db --user=root --datadir=/usr/local/arm/mysql/var
2)相关文件读写权限问题
/usr/local/arm/mysql/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
将这个目录mysql文件夹权限改为666就可以了。
给MySQL增加密码
./mysqladmin -u root password 123456
3)‘Got a packet bigger than 'max_allowed_packet' bytes QMYSQL3:Unable to execute statement’
修改/etc/my.cnf中的max_allowed_packet,然后重启mysql服务器/etc/mysql.server restart --user=root
注意:以上设置已经放到我们主机上的根文件系统了,以后下载后这些内容都存在文件系统中,无需每次手动设置。
进入数据库测试
./mysql -u root –p
然后输入密码即可进入数据库命令行操作界面。
4. 远程连接数据库
在windows电脑上使用navicat软件来远程连接i.MX6开发板中运行的MySQL数据库。
第一次连接时会出一个1130的错误:
ERROR 1130: Host '192.168.1.189' is not allowed to connect to thisMySQL server
解决方法:
进入数据库命令行,设置root用户任何IP地址都可以访问:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRA NT OPTION;
flush privileges;
这样就可以远程操作MySQL数据库了。