1. Install MySQL
In Linux, the complete MySQL development requires the installation of the server side, if the installation of the client is nothing bad. Search for MySQL directly in the Software Center and select the client and server.
The server prompts you to set a password for the root user during installation.
I am using MySQL, and the user name and password are stored in a database named MySQL, which can only be seen at the Administrator level.
If you enter MySQL directly in the terminal, the error 1045 (28000) may be displayed. This is because you access the database with your own user name, and currently the database has only one root user. It doesn't matter. If necessary, you can add a user:
Mysql-uroot-p --> Log On As A root user
Grant usage on *. * to dummy @ localhost; --> authorize a user named dummy to log on locally. Replace the user name with your own user name.
However, at this time, MySQL only has common permissions, and it is not possible to create a database or operate on MySQL. If you really need to grant it administrator permissions, you can view the relevant information on your own.
2. Install the MySQL driver of QT.
Method 1: directly sudo apt-Get install libqt4-sql-mysql, which is the MySQL driver of qt4, you do not have to compile it yourself, but may download some additional things.
Copy/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql. So to your qtsdk sqldrivers directory. At that time, I directly installed it with normal permissions. The directory is :~ /Qtsdk/desktop/QT/473/GCC/plugins/sqldrivers
Method 2: in fact, you can also sudo apt-Get download libqt4-sql-mysql, extract the package, and then search out the so file to directly copy it there.
Method 3: Compile according to the official method, but it does not seem feasible because the new version of qtsdk does not have the src directory and does not have the MySQL driver by default.
3. Try a demo.
Remember to add SQL in QT + = in the Pro file; otherwise, qmake will not find the relevant SQL part.
Article transferred from: http://www.cnblogs.com/qianyuming/archive/2011/08/13/2137402.html