Port MySql to the embedded Linux platform _ MySQL

Source: Internet
Author: User
Tags mysql backup
Port MySql to the embedded Linux platform bitsCN.com

Recently in the attendance machine system, hardware used cortex-A8, haha, in fact, is a bit wasteful, 2410 can be. Therefore, we need to consider the storage of attendance data, which was originally intended to be stored in the sqlite database. However, we later found that this database is only a local database and cannot be accessed over the Internet. in this case, the data client on the server cannot be accessed through a remote connection to the database. However, you can also use other methods, such as the socket method. the server sends the data requested by the client to the client, however, it is troublesome to sample the MySql database later, which involves the migration of the MySql database.

Search on the internet, find an article, I just according to the method step by step successfully transplanted the MySql-5.1.51 version, the following is the original

MySQL does not have a specific version for ARM, and there is no official documentation for porting it to ARM. Therefore, for the moment, please refer to this document:

Http://blog.chinaunix.net/space.php? Uid = 9701860 & do = blog & id = 285428, because after MySQL5.5, the compiled cmake is no longer used. /configure, so you have to switch back to support. /configure version. the 5.1.51 version is used here.

Perform the following steps to complete the migration:

1) Download mysql5.1.51:

Http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/mysql-5.1.51.tar.gz

2) install the compiler: The 4.3.3 compiler provided by EmbedSky is used. Gcc and others are included in Fedora14.

3) compile the mysql backup for the PC version

A) unzip the mysql-5.1.51 to/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 note that you do not need to run make install here to use the gen_lex_hash library in the pc version.

E) rename the folder mysql-5.1.51 to mysql-5.1.51-pc standby. (Save gen_lex_hash for separate backup)

F) the document says that there will be errors, but I did not encounter it during compilation. The only problem is that the arm version is compiled, an error is reported when you re-compile the pc version by modifying the folder name.

4) compile the ncurses of the arm version.

A) download ncurses-5.9.tar.gz: ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz

B) decompress to/opt/: tar zxvf ncurses-5.9.tar.gz c) cd ncurses-5.6

D)./configure-host = arm-linux-prefix =/usr/local/ncurse-enable-static e) make

F) make install

This is installed because the cross-compilation process of mysql requires the support of this database.

5) compile an arm version of mysql

A) tar zxvf mysql-5.1.51.tar.gz

B) cd mysql-5.1.51

C) modify the configuration file: open configure, you can use gedit configure

There are similar codes in the vicinity of lines 26,453rd, lines 48175, lines 48282, and lines 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 changed the code:

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 pay attention to the fact that there are four parts of this code that need to be completely removed.

D) configuration, directly applied to other people's configuration methods:

Configure. /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-example -- with-charset = gb2312 -- with-extra-charsets = ascii, latin1, utf8

E) modify opt/mysql-5.1.51/SQL/SQL _parse.cc: Add # define STACK_DIRECTION 1 before row 5646

If you modify this statement, the following error occurs: SQL _parse.cc: 5646: 21: operator '<'has no left operand, because the macro variable STACK_DIRECTION does not have an initial value defined, set STACK_DIRECTION to 1 in arm.

Note: the "# define STACK_DIRECTION 1" sentence here cannot be added at the beginning of SQL _parse.cc, but should be added to the corresponding row according to the error message, the row number I encountered is different from the one I encountered in other people's documents.

F) copy the PC version of gen_lex_hash file to the current folder: 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

Otherwise, an error occurs:

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 because the arm version cannot run on the pc.

Note: in other people's documents, you only need to copy gen_lex_hash, but after I tried it many times, the above error message will still appear. after copying lex_hash.h, no error will be reported. In addition, touch must be done, because the compiler should not compile and overwrite the copied files.

G) Make

H) Make install

6) port the corresponding file to the ARM platform

A) copy/usr/local/mysql from the pc to the same directory on the development board. I used nfs debugging, so the following command is required:

Cp-r/usr/local/mysql/opt/EmbedSky/root_nfs/usr/local/mysql

B) package and back up the compiled mysql database of arm to the host Directory:

Tar-zcvf mysql-arm-5.1.51.tar.gz mysql

C) copy the configuration file template Copies files from one location to another in the source code. the configuration file template)

Cp/opt/mysql-5.1.51/support-files/my-medium.cnf/opt/EmbedSky/root_nfs/etc/my. cnf

(The Directory here refers to the nfs debugging path settings), my. the cnf storage path is recommended in the manual. the path described in MySQL compiled in pc is not a global configuration. "# You can copy this file to/etc/my. cnf to set global options, mysql-data-dir/my. cnf to set server-specific options (in this installation this directory is/usr/local/mysql/var) or ~ /. My. cnf to set user-specific options. "For more information about the configuration file modification, see section 4.2.3.3. Using Option Files in the mysql5.1 English manual. The data directory is in:/var/lib/mysql installation directory is in:/usr/local/mysql

I tried to comment out some InnoDB configurations. However, after these settings are modified, an error is reported, and the error is returned.

D) run mysql_install_db (see 2.13. Post-Installation Setup and Testing in the manual)

Cd/usr/local/mysql/bin (Development Board path). the following error occurs when running mysql_install_db-u root: neither host 'embedded Sky' 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, the main reason is that the hostname in the development board environment is EmbedSky, rather than Federa14, therefore, mysql automatically considers that the operation in the operating system may be incompatible. There are two solutions:

First, run hostname fedora14 to cheat hostname; second, run mysql_install_db-u root-force. I used the second method: bin/mysql_install_db -- user = root -- force -- basedir =/usr/local/mysql -- datadir =/var/lib/mysql

An ERROR occurred in the middle: 150713 21:06:39 [ERROR]/usr/local/mysql/libexec/mysqld: unknown variable 'innodb _ data_home_dir =/usr/local/mysql/var /', find out the cause is my. the configuration related to InnoDB is commented out in cnf.

E) manually create mysqld/mysqld. pid. manually create:

Mkdir/var/run/mysqld

Touch/var/run/mysqld. pid

This step is not required. But I did.

F) copy the startup file to the source code.

Cp/opt/mysql-5.1.51/support-files/mysql. server/opt/EmbedSky/root_nfs/etc/init. d/mysqld modify this mysqld

For details, see 4.3.1. mysqld-The MySQL Server in The manual.

After basedir and datadir are added, and pid-file =/var/run/mysqld. pid is modified, assign sufficient permissions to the new mysqld: Chmod + x mysqld.

G) enable the MySQL service on the development board.

The development board does not support service commands, so service mysql start is invalid. Run./etc/init. d/mysqld start.

However, the following error occurs after the command is initially run:

Starting MySQL... ERROR! Manager of pid-file quit without updating file.

For a long time, go to the development board directory/var/lib/mysql to check the error log file [hostname]. err, the error log file in my system is EmbedSky. err:

150713 21:04:49 [ERROR] Fatal error: Can't change to run as user 'mysql'; Please check that the user exists!

Possible cause: groupadd mysql cannot be executed on arm linux. Therefore, you need to solve this problem using the following methods: cd/var/lib/mysql

Ls-la can see that there is no mysql in the attributes, so use the following command: adduser mysql

Chown mysql: mysql-R/var/lib/mysql

Then enable the mysql service, and an ERROR still occurs! Manager of pid-file quit without updating file. view the EmbedSky. err log again, with one more:

150714 2:48:04 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use

150714 2:48:04 [ERROR] Do you already have another mysqld server running on port: 3306?

Apparently, the mysql process has attempted to open port 3306, so it is occupied. you need to kill the process, simply restart the development board, and then run it. /etc/init. d/mysqld start, which can be opened perfectly.

H) set the soft connection so that mysql, mysqldump, and mysqladmin commands can be directly stored in the shell of the Development Board.

Connect to run

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

7) test MySQL on the ARM platform.

A) mysqladmin-u root password Hahahaha the last one is my password (set the password)

B) mysql-h 127.0.0.1-u root-p or mysql-h localhost-u root-p.

Enter the mysql environment.

C) mysql> show databases

The above method can basically complete cross-compilation, but some problems may occur during later running, prompting Permission denied, the main cause of this error is that the root account is used by default after the development department is started, but the mysql account you added does not have the root account permission, so you do not have the permission to execute it, the solution is to add your account to the root user group. when modifying the user group, note that the usermod command may not be provided in the file system, in this case, you need to use vi to open the/etc/passwd file under the Development Board file system, and change the mysql account you created to the root user group so that you can run it, run mysql sucess again...

Congratulations, mysql has finally been transplanted, but if you want to use Qt development on the development board, you also need to transplant the embedded mysql Qt driver, that is, generate the libqsqlmysql. so file through cross-compilation.

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.