Posts Tagged MySQL

Alternate to FIND_IN_SET for non-MySQL databases

Missing MySQL

Missing MySQL

If you are MySQL user initially at the beginning of your career and later on as the career progresses got in touch with other RDBMS then you might miss MySQL's FIND_IN_SET function badly. :)

What MySQL's FIND_IN_SET does is it returns position of the matched element in the SET. That SET of items must be comma-separated.

For example take following code into consideration:

SELECT FIND_IN_SET('b','a,b,c,d');

It will return "2" as the result. So generally what we have been doing is we use it not to find whether particular element is at what position in the comma-separated list but just to find simply that whether item exists in the list at all or not?

For that we use SQL something like following:

SELECT COUNT(0) FROM products WHERE FIND_IN_SET('7', category_id);

Above query will give you count of records which are having category_id 7 along with or without other categories. In table records might have values comma-separated like '4,5,7' or '7' or '2,7,8' or anything. So above expression in WHERE will return value greater than "zero" (0) and that row will be returned in result or calculated in count. Here category_id in products table is of type varchar.

Now when we are not using MySQL many times we can get similar result if we are not worried about the position of the item in the set but just want to make sure that it exists or not. It can be achieved with following SQL statement. Read the rest of this entry »

Tags: ,

Setting up PHP, MySQL, Apache with most up-to-date WAMP Package

WAMP Packages

WAMP Packages

Availability of WAMP packages is not a new story, they are here since the beginning of last decade now. EasyPHP, Wamp, XAMPP and dozens of them. Find comparison of WAMP packages on Wikipedia here.

We are here not to discuss all of them, just top 3 to 5 which are active and we can use them reliably for development or optionally for production purpose or both.

Having WAMP stake up-to-date on production environment is important as we are using open-source technologies and there are few to hundreds of critical to non-critical bugs are being fixed with every new release of the software, and if it's development environment we would like to test new features when they're hot.!

Zend Server, Zend Server Cluster Manager and Zend Server Community Edition:

Zend Server (CE)

Zend Server (CE)

All 3 editions are highly reliable and ready for production usage. I have tried both Zend Server and ZS-Community Edition, Zend Server - Commercial version is pre-tweaked for performance on production environment and Community Edition do not have some of the goodies. But that does not stop you or me from using Zend Server - CE on production. Zend Server comes with beautiful web-panel to administer, control and configure server from the browser itself. We can change PHP and Apache parameters, check server status and even restart service from within browser itself, this feature makes it good choice for remote server administration.

Zend Server - CE is as good for development as it is for production. It comes as Apache and PHP package where MySQL is an optional download during the installation wizard.

The Uniform Server:

The Uniform Server

The Uniform Server

Uniform Server is comparatively new kid on the floor and highly configurable for both development and production use. It comes with system tray using which we can switch Apache and PHP configuration files from development to production or back and forth.

It comes in both VC6 and VC9 binaries for Windows and I must say it's most up-to-date WAMP package so far (I mean next or equal to Zend). Rest of all WAMP packages take week to months to bundle latest version of Apache, PHP or MySQL but I have observed Uniform Server very quick with that. This is main benefit if you are really looking for such option to use on production server.

Installation is simplest - extract and done. Comes with minimum, no big bucket (just 11-13MB in size).

Comes with some handy plug-ins for FTP, Resin, Tomcat etc. It has e-Accelerator packed with it is recommended for production use.

Read the rest of this entry »

Tags: , , , ,

MySQL5 Problem while creating new user – SQL Error (1133): Can’t find any matching row in the user table

MySQL 5.5.8

MySQL 5.x

When we use GUI tools like HeidiSQL with MySQL Windows binaries - setup from MySQL.com might be creating issues like these. Because recently faced errors #1364 and #1133 both became visible while I did clean install of MySQL by downloading Windows Installer for MySQL 5.5.8 from MySQL.com and not while using it with MySQL as part of some WAMP package.

It must be because the way some parameters come as defaults while we use MySQL installer or might be the way we configure the MySQL Instance using MySQL instance configuration wizard.

SQL Error (1133): Can't find any matching row in the user table

Now we will get above error message due to SQL_MODE variable value set to NO_AUTO_CREATE_USER, you can check value for your server's sql-mode by using following SQL:

SHOW VARIABLES LIKE 'SQL_MODE'
 

Output can be something like STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION as we can specify multiple values separated by comma. NO_AUTO_CREATE_USER won't let you create users with empty passwords.

Prevent the GRANT statement from automatically creating new users if it would otherwise do so, unless a nonempty password also is specified. (Added in MySQL 5.0.2)

If you're using HeidiSQL 6 or earlier you won't be able to create users even if you specify password due to the way HeidiSQL constructs the SQL to create user. See the screen-shot: Read the rest of this entry »

Tags: , ,

MySQL 5.5.8 – Problem while Creating new User (SQL Error (1364): Field ‘authentication_string’ doesn’t have a default value)

MySQL 5.5.8

MySQL 5.5.8

I have just downloaded and setup MySQL 5.5.8 community server for Windows (32bit Installer) from MySQL official downloads. After downloading while I tried connecting it with HeidiSQL 5.x I got following error "Problem while Creating new User (SQL Error (1364): Field 'authentication_string' doesn't have a default value)".

It seems like it's a problem with HeidiSQL-5, probably due to the fact that table schema for mysql.users table might be changed in MySQL 5.5.8. You might see something like following if you're using HeidiSQL-5.

MySQL5.5 > Create User error while using HeidiSQL 5.0

MySQL5.5 > Create User error while using HeidiSQL 5.0

Solution: There are 2 ways to fix the problem:

A) Download HeidiSQL 6.0 and try creating user again. Read the rest of this entry »

Tags: , ,

MySQL 5.5 available for production

Oracle MySQL 5.5.8 GA

MySQL 5.5.8 GA

Back in December when I updated my twitter status to announce MySQL 5.5 general availability, I was very happy at that moment. It was the first major and much awaited release of MySQL after Oracle - the database giant acquired Sun (and so MySQL). Though MySQL 6.0 is not an active project right now and there are many strategic changes after Oracle's acquisition of Sun for MySQL's development road-map, but as a AMP developer it was news to be happy about.

Good to see MySQL founder Michael "Monty" Widenius, has forked MySQL as MariaDB, which is binary compatible (drop-in replacement) with MySQL. Good to see open-source efforts to keep the momentum alive.

Moving back to MySQL, with version 5.5 there are lot of new enhancements including performance improvements for both MyISAM and InnoDB storage engine. InnoDB gets updated to latest version InnoDB 1.1. There are many improvements with replication and couple of new feature addition with replication as well. I have been using MySQL-Replication since long time (3 years now) and I am excited about the replication heartbeat and all new improvements which are made in that direction.

Some of the highlights from MySQL.com about 5.5 are as following:

MySQL Database 5.5 delivers enterprise features, including:

  • Improved! Up to 1500% faster performance on Windows
  • Improved! Up to 370% faster performance on Linux
  • Improved! Better scalabilty on modern, multi-core, multi-CPU hardware
  • New! Performance Schema for monitoring MySQL server run-time performance
  • New! Semi-synchronous replication to ensure data consistency and redundancy
  • New! Replication Heartbeat to immediately uncover replication interruptions
  • New! Partitioning options for faster lookups
  • New! Easier development and debugging of stored procedures, functions, and triggers
  • Reliability requiring little or no intervention to achieve continuous uptime
  • Ease of use with "15 minutes to success" installation and configuration
  • Low administration with very little database maintenance required
  • Replication providing flexible topologies for scale-out and high availability Read the rest of this entry »

Tags: , , ,

Using Views to avoid cross database connection – MySQL

Table Views can be used as an unconventional way to avoid cross/multiple database connections sometimes..! Yes, it can be. I came across such case and found that it can be handy in some simple cases when we just want to avoid connection to another database on the same MySQL server and we can't afford to create that table in the same database due to some reasons.
Views

Views - Image courtesy Flickr

It's very simple. You can have your table "contacts" in "my_db" database and you want to access this table (not just read need to write/insert and update too) in another database named "another_db".
You can have your "contacts" table in "my_db" with following syntax: Read the rest of this entry »

Tags: ,

HeidiSQL 5.1 – good has got better

HeidiSQL

HeidiSQL

HeidiSQL has been excellent SQL Administration and Development tool so far for me. HeidiSQL has active development team which keeps adding new feature and upgrading and correcting bugs to get us the great tool for MySQL development.

I have been using HeidiSQL since more than three and half years now and I am really happy with it. I must say that we work with heavy database consisting of more than 400 tables and database size exceeding few GBs but HeidiSQL has never let us down. I have tried loading my development database with phpMyAdmin and SQL Buddy both but they just failed to load such a large database with few hundreds of tables..! But with HeidiSQL I never had any problem except I got some crashing sometime in newer 5.x version but I am sure all such things will be fixed in coming builds. I am not telling that there are no other good tools are available in the market but HeidiSQL is in premium open-source tool at free of cost. I remember I had written a post on HeidiSQL 4.x more than a year ago and today we are up with HeidiSQL 5.1. Read the rest of this entry »

Tags: , ,

Paying the bills.!