您的位置:首页 > 数据库 > MySQL

【数据库】mysql移植

2018-01-04 15:03 190 查看
一、源码下载

1、下载mysql源码

源码下载地址:选择版本:5.1.72(这是个老版本,高版本需要使用cmake)
https://cdn.mysql.com/archives/mysql-5.1/mysql-5.1.72.tar.gz
历史版本下载地址

源码官网地址,在Operating System中选择Source code
https://downloads.mysql.com/archives/community/
2、下载ncurses,选择5.9版本

官网地址
http://ftp.gnu.org/pub/gnu/ncurses/
下载地址
http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
二、交叉编译

1、编译PC版的mysql备用

1.1 解压mysql-5.1.72.tar.gz后进入目录mysql-5.1.72中,执行:./configure -prefix=/usr/local/mysql

1.2 执行:make

1.3 复制mysql-5.1.72 为mysql-5.1.72_pc备份

2、交叉编译ncurses,注意路径是本人电脑环境的路径(/home/lisa/1-tools/install/ncurses-5.9),需要根据自己的做更改

2.1 解压ncurses-5.9.tar.gz后进入目录ncurses-5.9中,

执行:./configure --host=arm-fsl-linux-gnueabi --prefix=/usr/local/ncurse -enable-static

2.2 执行:make

2.3 进入root权限:su

2.4 配置环境变量PATH:根据自己电脑环境来配置

export PATH=$PATH:/home/lisa/1-tools/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/

2.5 执行:make install

3、交叉编译mysql

3.1 解压mysql-5.1.72.tar.gz后进入目录mysql-5.1.72中;

3.2 修改configure,共四处

3.2.1

----------------------------------------------------------------------------------------------

26302   if test "$cross_compiling" = yes; then

26303   echo "skip...!"

26304 #  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5

26305 #$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}

26306 #{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling

26307 #See \`config.log' for more details." >&5

26308 #$as_echo "$as_me: error: cannot run test program while cross compiling

26309 #See \`config.log' for more details." >&2;}

26310 #   { (exit 1); exit 1; }; }; }

26311 else

-------------------------------------------------------------------------------------------------

3.2.2

-------------------------------------------------------------------------------------------------

48121   if test "$cross_compiling" = yes; then

48122   echo "skip...!"

48123 #  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5

48124 #$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}

48125 #{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling

48126 #See \`config.log' for more details." >&5

48127 #$as_echo "$as_me: error: cannot run test program while cross compiling

48128 #See \`config.log' for more details." >&2;}

48129 #   { (exit 1); exit 1; }; }; }

48130 else

-------------------------------------------------------------------------------------------------

3.2.3

-------------------------------------------------------------------------------------------------

48228   if test "$cross_compiling" = yes; then

48229   echo "skip...!"

48230 # { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5

48231 #$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}

48232 #{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling

48233 #See \`config.log' for more details." >&5

48234 #$as_echo "$as_me: error: cannot run test program while cross compiling

48235 #See \`config.log' for more details." >&2;}

48236 #   { (exit 1); exit 1; }; }; }

48237 else

-------------------------------------------------------------------------------------------------

3.2.4

-------------------------------------------------------------------------------------------------

48442   if test "$cross_compiling" = yes; then

48443   echo "skip...!"

48444 # { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5

48445 #$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}

48446 #{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling

48447 #See \`config.log' for more details." >&5

48448 #$as_echo "$as_me: error: cannot run test program while cross compiling

48449 #See \`config.log' for more details." >&2;}

48450 #   { (exit 1); exit 1; }; }; }

48451 else

-------------------------------------------------------------------------------------------------

3.3 执行configue,注意:安装路径和引用ncurses-5.9库的路径,是本人电脑环境的路径,需要根据自己的做更改

./configure --host=arm-fsl-linux-gnueabi --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

3.3.1 注意:configure -help中有如下编译选项,本次未添加,未验证:--with-embedded-server --with-machine-type

3.4 修改sql/sql_parse.cc,添加如下代码

-------------------------------------------------------------------------------------------------

5741 #define STACK_DIRECTION 1

-------------------------------------------------------------------------------------------------

3.5 将pc版中gen_lex_hash文件到当前文件夹

$cp  ../mysql-5.1.72_pc/sql/gen_lex_hash sql/

$touch –m sql/gen_lex_hash  

$cp  ../mysql-5.1.72_pc/sql/lex_hash.h sql/

$touch –m sql/lex_hash.h

3.6 make

3.7 进入root权限:su

3.8 配置环境变量PATH:根据自己电脑环境来配置

export PATH=$PATH:/home/lisa/1-tools/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/

3.9 执行:make install

三、移植到arm平台

1、将库拷贝到开发板上

$ cd /usr/local/

$ sudo tar -zcvf mysql-arm-5.1.72.tar.gz mysql/

将mysql-arm-5.1.72.tar.gz拷贝到开发板上,解压到/usr/local下:tar -xf mysql-arm-5.1.72.tar.gz -C /usr/local

2、配置环境变量

修改/etc/profile,在文件添加:

-------------------------------------------------------------------------------------------------

export PATH="$PATH:/usr/local/mysql/bin"

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/mysql/lib/mysql"

-------------------------------------------------------------------------------------------------

3、创建配置文件 /etc/my.cnf

添加内容如下:

-------------------------------------------------------------------------------------------------

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

port = 3306

datadir=/var/lib/mysql

socket=/tmp/mysql.sock

user=root  

old_passwords=1

skip-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

log-bin=mysql-bin

binlog_format=mixed

server-id = 1

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 20M

sort_buffer_size = 20M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

--------------------------------------------------
4000
-----------------------------------------------

4、安装mysql数据

#mkdir -p /var/run/mysqld/

#mkdir -p /var/log/

#touch /var/run/mysqld/mysqld.pid

#mysql_install_db --user=root --force --basedir=/usr/local/mysql --datadir=/var/lib/mysql

5、添加启动文件

将源码中的启动文件:拷贝support-files/mysql.server,为/etc/init.d/mysqld

修改mysql.server内容:

-------------------------------------------------------------------------------------------------

     basedir=/usr/local/mysql

     datadir=/var/lib/mysql

     pid_file=/var/run/mysqld/mysqld.pid

     server_pid_file=/var/run/mysqld/mysqld.pid

-------------------------------------------------------------------------------------------------

6、重启开发板

四、使用mysql

1、初始化mysql数据库

 mysql_install_db --user=root --force --basedir=/usr/local/mysql --datadir=/var/lib/mysql

-------------------------------------------------------------------------------------------------

root@freescale ~$ mysql_install_db --user=root --force --basedir=/usr/local/mysql --datadir=/var/lib/mysql

Installing MySQL system tables...

170612 14:25:55 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

OK

Filling help tables...

170612 14:25:55 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

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:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h freescale password 'new-password'

Alternatively you can run:

/usr/local/mysql/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 /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

-------------------------------------------------------------------------------------------------

2、启动mysql数据库

/etc/init.d/mysqld start

3、访问mysql

mysql -u root

mysql>use mysql

mysql>show tables;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息