ARM above remote access MySQL database (reproduced)

Source: Internet
Author: User
Tags echo command rar

It is normal to use MySQL on a PC, but porting to the ARM board always prompts you not to load the MySQL driver. No matter where I put the library file, I can't use it. When looking for information, inadvertently found an article, finally can use MySQL on Qt.

1. Prepare MySQL driver source code. I have extracted it. Download file: Mysql-source.rar
After extracting a total of 9 files.
My_alloc.h mysql_com.h mysql_version.h qsql_mysql.h my_list.h mysql.h mysql_time.h qsql_mysql.cpp typelib. H
Copy the 9 files to the project catalog and join the project.
2. Download the MySQL library file.
Arm version: Mysql-lib-arm.rar
PC version: Mysql-lib-pc.rar
After decompression, there is a folder respectively. Then put the path of the two folder into the/usr/local/mysql directory.
3. Add to the environment variable $ld_library_path. The ARM version, in addition to being compiled on a PC, is also downloaded to the Development Board when it is running. The Development Board also joins the path to the $ld_library_path

(1) running Env at Ubuntu Terminal, found that there is no Ld_library_path this environment variable (2) to open a new terminal, enter the command echo $LD _library_path, the result is blank.
(3) Add a directory via export, enter the command at the terminal, if the PC version of the program is added directory: Export ld_library_path=/usr/local/mysql/mysql-lib-pc, If you compile the ARM board, change the directory to Mysql-lib-arm
Close the terminal, open a new terminal, enter the Echo $LD _library_path command, then display as blank. Description Adding a directory with a shell directive is not available after you close the terminal.
(4) You can also edit the ~/.profile file to add content:
If [-D "$HOME/lib"]; Then
Export ld_library_path= "/USR/LOCAL/MYSQL/MYSQL-LIB-PC"
Fi
When using CTRL+ALT+F1 to log in to Tty1, use the echo $LD _library_path to see the environment variables in place.
But in the terminal, enter the Echo command, which is still blank. environment variable settings have no effect.

(5) If you do not want to set Ld_library_path every time city a shell, you can edit the ~/.bash_profile file:

$ VI ~/.bash_profile

Add to:
Ld_library_path=/usr/local/mysql/mysql-lib-pc
Export Ld_library_path
These two lines, after completion. Bash_profile are as follows:
#. Bash_profile
# Get the aliases and functions
If [-f ~/.BASHRC]; Then
. ~/.bashrc
Fi
# User specific environment and startup programs
Path= $PATH: $HOME/bin
Ld_library_path=/usr/local/mysql/mysql-lib-pc
Export PATH
Export Ld_library_path
And then run
$ source ~/.bash_profile on the line.
4. Then return to the project file.
Modify a project file (. Pro file) Finally add a sentence LIBS + =-l/usr/local/mysql/mysql-lib-pc-lmysqlclient
Where the red part is the path to the library file you just unzipped. If you are compiling the PC version of the path to write PC versions, compile arm to write the arm version of the path.
5. The preparation is complete, and then the program can be written. and normally connect to MySQL almost. In the code that connects to MySQL, this is now the case.
Join #include "qsql_mysql.h"


MYSQL *conr=mysql_init (NULL);
Mysql_real_connect (conr,null,null,null,null,0,null,0);
Qmysqldriver *drvr = new Qmysqldriver (CONR);
Qsqldatabase db=qsqldatabase::adddatabase (DrvR);
Db.sethostname ("192.168.0.210");
Db.setdatabasename ("test");
Db.setusername ("root");
Db.setpassword ("");
if (!db.open ())
{
Qdebug () << "error";
Exit (1);
}
Else
Qdebug () << "OK";
6. Compile the program on the PC, there may be problems, you need to add the # include header files, and in the compilation of the ARM board program, there will be problems, saying that several functions are not declared.
Qsql_mysql.cpp 1417 Line: function Numericalprecisionpolicy () is not declared:
I've blocked the program directly because I don't need to use the query functionality it provides:
/*switch (Numericalprecisionpolicy ()) {
Case QSQL::LOWPRECISIONINT32:
V=qvariant (dbl). ToInt ();
Break
Case Qsql::lowprecisionint64:
v = qvariant (dbl). Tolonglong ();
Break
Case Qsql::lowprecisiondouble:
v = qvariant (dbl);
Break
Case Qsql::highprecision:
Default
v = Val;
OK = true;
Break
}*/
Another is: Qsql_mysql.cpp 1417 line:
/*if (isidentifierescaped (table, Qsqldriver::tablename))
Table = stripdelimiters (table, qsqldriver::tablename); */
7. Finally, all issues are resolved, the program can be run, and the pro-test is available.

8. The library file may not be found at compile time, and a soft connection will be created under the appropriate folder.

ARM above remote access MySQL database (reproduced)

Related Article

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.