Linux下完整的MySQL开发需要安装服务器端,如果安装客户端也没什么不好。直接在软件中心搜mysql,把client和server选上。
环境说明:ubuntu 10.04.2
QtSDK (1.5G安装包的那个)
mysql5.1
1.安装MySQL
Linux下完整的MySQL开发需要安装服务器端,如果安装客户端也没什么不好。直接在软件中心搜mysql,把client和server选上。
server在安装时会提示为root用户设置密码,设一个好了。
我使用的是mysql5.1版本,用户名密码存储在一个叫mysql的数据库里,只有管理员级别才能看到。
如果直接在终端中输入 mysql,可能会提示ERROR 1045 (28000),这是因为这时候你是以自己用户名访问数据库,而目前数据库中只有一个root用户。没关系,如果有必要,可以添加一个用户进去:
mysql -uroot -p -->以root用户登录
grant usage on *.* to dummy@localhost; -->授权名为dummy的用户本地登录,这里换成自己的用户名就可以了
不过这时候直接mysql只有普通的权限,创建数据库、操作mysql都是不可以的,如果真有将其赋予管理员权限的需要,可以自己查阅有关资料。
2.安装Qt的MySQL驱动。
方法一:直接sudo apt-get install libqt4-sql-mysql ,这是Qt4的mysql驱动,就不用自己费劲编译了,不过可能会额外下载一些东西。
将 /usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so拷贝到你的QtSDK sqldrivers目录下,我当时是直接用普通权限安装,目录为:~/QtSDK/Desktop/Qt/473/gcc/plugins/sqldrivers
方法二:其实你也可以sudo apt-get download libqt4-sql-mysql,把包解压缩,然后把里面的so文件搜出来直接拷贝到那里。
方法三:乖乖按照官方方法编译,但是貌似可行性不大,因为新版本的QtSDK并没有src目录,默认也没有mysql的驱动。
3.做个demo试一下
记得在pro文件中 QT +=那里加上sql,否则qmake是不会去找sql的相关部分的
代码如下:
#include
#include
#include
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("study");
db.setUserName("root");
db.setPassword("tyh");
if(!db.open()){
qDebug()}else{
qDebug()}
return a.exec();
}
这里study这个数据库之前我已经创建过了,如果连接成功,就会显示Database connection established。 我是建立的控制台程序哈。

The main difference between MySQL and SQLite is the design concept and usage scenarios: 1. MySQL is suitable for large applications and enterprise-level solutions, supporting high performance and high concurrency; 2. SQLite is suitable for mobile applications and desktop software, lightweight and easy to embed.

Indexes in MySQL are an ordered structure of one or more columns in a database table, used to speed up data retrieval. 1) Indexes improve query speed by reducing the amount of scanned data. 2) B-Tree index uses a balanced tree structure, which is suitable for range query and sorting. 3) Use CREATEINDEX statements to create indexes, such as CREATEINDEXidx_customer_idONorders(customer_id). 4) Composite indexes can optimize multi-column queries, such as CREATEINDEXidx_customer_orderONorders(customer_id,order_date). 5) Use EXPLAIN to analyze query plans and avoid

Using transactions in MySQL ensures data consistency. 1) Start the transaction through STARTTRANSACTION, and then execute SQL operations and submit it with COMMIT or ROLLBACK. 2) Use SAVEPOINT to set a save point to allow partial rollback. 3) Performance optimization suggestions include shortening transaction time, avoiding large-scale queries and using isolation levels reasonably.

Scenarios where PostgreSQL is chosen instead of MySQL include: 1) complex queries and advanced SQL functions, 2) strict data integrity and ACID compliance, 3) advanced spatial functions are required, and 4) high performance is required when processing large data sets. PostgreSQL performs well in these aspects and is suitable for projects that require complex data processing and high data integrity.

The security of MySQL database can be achieved through the following measures: 1. User permission management: Strictly control access rights through CREATEUSER and GRANT commands. 2. Encrypted transmission: Configure SSL/TLS to ensure data transmission security. 3. Database backup and recovery: Use mysqldump or mysqlpump to regularly backup data. 4. Advanced security policy: Use a firewall to restrict access and enable audit logging operations. 5. Performance optimization and best practices: Take into account both safety and performance through indexing and query optimization and regular maintenance.

How to effectively monitor MySQL performance? Use tools such as mysqladmin, SHOWGLOBALSTATUS, PerconaMonitoring and Management (PMM), and MySQL EnterpriseMonitor. 1. Use mysqladmin to view the number of connections. 2. Use SHOWGLOBALSTATUS to view the query number. 3.PMM provides detailed performance data and graphical interface. 4.MySQLEnterpriseMonitor provides rich monitoring functions and alarm mechanisms.

The difference between MySQL and SQLServer is: 1) MySQL is open source and suitable for web and embedded systems, 2) SQLServer is a commercial product of Microsoft and is suitable for enterprise-level applications. There are significant differences between the two in storage engine, performance optimization and application scenarios. When choosing, you need to consider project size and future scalability.

In enterprise-level application scenarios that require high availability, advanced security and good integration, SQLServer should be chosen instead of MySQL. 1) SQLServer provides enterprise-level features such as high availability and advanced security. 2) It is closely integrated with Microsoft ecosystems such as VisualStudio and PowerBI. 3) SQLServer performs excellent in performance optimization and supports memory-optimized tables and column storage indexes.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
