Tag Archive : mysql

/ mysql

Creating MySQL Driver for Qt5 on Windows

December 9, 2015 | Article | No Comments

This article will discuss on how to create MySQL driver for Qt4 on Windows using MinGW. This article is motivated by the fact that MySQL driver isn’t shipped by default on Qt5.

All the works are done using:

  1. Windows 8
  2. MinGW 4.8.1 (TDM)
  3. Qt 5.1.1
  4. MySQL 5.6.14.0

Actually my Windows 8 is 64-bit, but all program we test here is 32-bit version (MinGW32, MySQL 32-bit).

Obtain Materials

For this article we need Qt libraries, Qt source code, and MySQL server.

Qt version I use is 5.1.1. You need to download two separate files (libraries and source code).

We also need MySQL server and the library. The version I use is 5.6.14 which you can download here.

The reason why I didn’t use the 64-bit version simply because my current project should produce 32-bit app. If you want to follow this article, make sure all the materials are 32-bit.

Installation the Materials

Installing Qt

Install Qt libraries. Installing default components would do alright. Although you can use full installation, but in this article we will use the default one. I select drive C:\ like default path and leave it to Qt. At the end, the Qt is installed as C:\Qt\Qt5.1.1

Next, extract the Qt sources to a folder you choose. Let’s extract it to the same folder as Qt libraries does. Which means, the target path is C:\Qt\Qt5.1.1. Rename the long name “qt-everywhere-opensource-src-5.1.1” to “sources”. Thus, we have C:\Qt\Qt5.1.1\sources.

Installing MySQL

Install MySQL. Select custom installation. At minimal, you need to install Client C API Library, the other components are optional. Let’s installed it under C:\Program Files (x86)\MySQL\MySQL Server 5.6

Building & Deploying

Open Qt command prompt, You should have one. It is like normal command prompt, except it has default Qt environment variable we need. Once you open it, you will be brought to your Qt directory.

Now execute following:

set mysql=C:\\PROGRA~2\\MySQL\\MYSQLS~1.6
cd C:\Qt\Qt5.1.1\sources\qtbase\src\plugins\sqldrivers\mysql\
qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro
mingw32-make

Once it is built successfully without error, you will have some fileson C:\Qt\Qt5.1.1\sources\qtbase\plugins\sqldrivers. They are:

  1. libqsqlmysql.a
  2. libqsqlmysqld.a
  3. qsqlmysql.dll
  4. qsqlmysqld.dll

For .dll files, move them to C:\Qt\QT5.1.1\5.1.1\mingw48_32\plugins\sqldrivers.

For .a files, move them to C:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib

Also, copy libmysql.dll from %mysql%\lib to C:\Windows

Testing

To use the driver, don’t forget to add QT += sql to project file, else it don’t work.

Check which drivers are available by this code:

#include <QtCore/QCoreApplication>
#include <QtSql>

int main() {
    QCoreApplication a(argc, argv);
    aDebug() << QSqlDatabase::drivers();
    return a.exec();
}

In previous article, we have discuss how to explore SQLite database using third party program, SQLite Manager on Mozilla Firefox. Now let’s cover another DBMS, MySQL.

In this article we will discuss about installation of SQL Explorer plugin for Eclipse. For this purpose I use:

  1. Slackware64 14.0
  2. Eclipse Juno
  3. SQL Explorer 3.6.1

However, unless you are not using Eclipse, the Operating System should give no problem.

Prerequisite

  1. MySQL DB

If you have not installed MySQL, please read related article first. This article will use assumption you have installed MySQL on your system.

Obtain the Material

SQLExplorer can be downloaded from it’s download page

The one we use is the 3.6.1 release, or you can direct download here.

Next is MySQL Connector Java. This will act as connector so the plugin can communicate to MySQL database. Download the connector from it’s download page: http://dev.mysql.com/downloads/connector/j/

At this point we have two package:

  1. sqlexplorer_plugin-3.6.1.zip
  2. mysql-connector-java-5.1.25.tar.gz (or mysql-connector-java-5.1.25.zip if you prefer to)

Installation

Open up terminal and go to your download page (place you have all the materials we need) then invoke these commands:

unzip sqlexplorer_plugin-3.6.1.zip
cp -R features plugin <eclipse path>

Replace the <eclipse path> with your actual eclipse installation path.

Next, we need to install the connector.

tar -xf mysql-connector-java-5.1.25.tar.gz
cd mysql-connector-java-5.1.25
cp mysql-connector-java-5.1.25-bin.jar /usr/share/mysql/

Now open up Eclipse and there should be a new perspective SQL Explorer.

Installing MySQL into FreeBSD

December 5, 2015 | Article | 1 Comment

On different article, we have discussed about how to configure MySQL on Slackware. In this article we will discuss about how to install MySQL server on FreeBSD machine.

If you want to building a Web Server (installing Apache and PHP) then you might want to install MySQL Database first.

MySQL is well-known as reliable, free open source Database Management. Most of web server use MySQL as Database backend.

For this, I use FreeBSD 8.3 amd64, but you can have any FreeBSD version and platform as you please. The MySQL we use would be 5.5 as provided on FreeBSD ports collection.

Installing the port

Installing MySQL is as easy as installing any ports. Do the following commands:

cd /usr/ports/databases/mysql55-server
make install

If you are going to do fresh installation, you will be prompted by installation options menu. The configuration I choose are list here:

  1. OPENSSL (Enable SSL support)

You might also want to install the client:

cd /usr/ports/databases/mysql55-server
make install

The configuration I choose are list here:

  1. OPENSSL (Enable SSL support)

Once you finish installing, you might find a mysqld script on /usr/local/etc/rc.d. MySQL then will store the data in /var/db/mysql

Starting MySQL

/etc/rc.conf must contain the following line to allow the MySQL server to start

mysql_enable="YES"

Once this line is there you can run the start up script with

/usr/local/etc/rc.d/mysql-server.sh start

Setting the root password

Normally, MySQL root account and anonymouse has no password on fresh install. Therefore we need to set password on it. If not, MySQL will give full access to the database server to anyone.

To set a password on the root accounts use

mysql -u root
mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');

Note that mysql> is prompt you got when you enter MySQL console.
To set a password for the root account use

mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

Managing your MySQL server with phpMyAdmin

If you are to lazy to use terminal and want to administrate Database graphically, you can use phpMyAdmin. To do that, you have to install Apache and PHP first. With this tool, you can manage MySQL database with web interface. It allows you to perform SQL queries, create new databases, add users, change privileges, backup and import data.

To install phpMyAdmin, you can invoke following commands:

cd /usr/ports/databases/phpmyadmin
make install

Set Up and Configuring MySQL in Slackware Linux

December 3, 2015 | Article | No Comments

MySQL is indeed one of popular database management system used worldwide. Not to mention it is open source and free to use. Practically, MySQL is often used together with PHP server-side scripting language, apache web server, and linux as the server platform.

For you who come from another distribution such as Ubuntu, Mint, Fedora, or even from another Operating System such as Windows or Mac, maybe you will be surprised. If you have done full slackware installation, you actually have install MySQL. MySQL Is shipped to default Slackware installation, but wait! We have to configure it first.

This article will discussed about how to properly configure your MySQL DBMS from zero to be available.

In this article, I am using:

  1. Slackware64-bit version 14.0 with multilib enabled

First, we need to check wether mysql user and mysql group already exist in the system. If you installed mysql during installation then you must have it

$ less /etc/passwd | grep mysql
mysql:x:27:27:MySQ

If you are prompted with something like that, then MySQL is already installed. If not, grab your installation DVD and search for the MySQL.

Now, we must create the initial database and set permission. Do this as root.

mysql_install_db --user=mysql

User specified by –user will own database files. Thus, it is important to set the user with the right one. If you are not do this, MySQL won’t be able to write to database. In Slackware, MySQL runs as user mysql by default.

Networking is disabled by default for security issue. If you want to allow network connections, you should comment out this line in /etc/rc.d/rc.mysqld

#SKIP="--skip-networking"

To start mysql, we must run the daemon. To run it, we simply execute a script on /etc/rc.d/ directory named rc.mysqld. Of course, you must check whether the file is executable or not. Once executed, you will have MySQL running:

/etc/rc.d/rc.mysqld start

Congratulation! MySQL has been successfully ran! Up to this point the MySQL is up but won’t behave as you need until you have configure it.

The Fresh installation of MySQL has a blank password for root of DB. Well, you know what it means, don’t you? A blank-password for root means your database is very vulnerable so we must give it password. To do so, do this:

mysqladmin -u root password 'your-new-password'

and do this also (for network access login)

mysqladmin -u root -h 'your-hostname' password 'your-new-password'

Try login using user root with your specified password.

Next thing to do is removing anonymous user. Anonymous user is by default a user which can access database with no authentication (for testing purpose). Better remove it as soon as possible. Run these command from mysql terminal.

mysql> use mysql
mysql> SELECT user, host FROM user;
mysql> DELETE FROM user WHERE host='localhost' AND user='';

And let me congratulate you again! You have properly configure MySQL for first-time use 🙂

Things to know

Default log is located at /var/lib/mysql/<hostname>.err.

You can also reset the password by save these lines as xath_user_modify.cnf:

UPDATE Mysql.USER SET Password=PASSWORD('Your new password') WHERE USER='root';
FLUSH PRIVILEGES;

Then load the saved file using:

/usr/bin/mysqld_safe --defaults-file="xath_user_modify.cnf"

 

Social media & sharing icons powered by UltimatelySocial