Archive for the 'Databases' Category

How to Backup and Restore (Export and Import) MySQL Databases Tutorial

July 21st, 2007

phpMyAdmin can be used to export or backup MySQL databases easily. However, if the database size is very big, it probably won’t be a good idea. phpMyAdmin allows users to save database dump as file or display on screen, which involves exporting SQL statements from the server, and transmitting the data across slower network connection or Internet to user’s computer. This process slow the exporting process, increase database locking time and thus MySQL unavailability, slow the server and may simply crash the Apache HTTPD server if too many incoming web connections hogging the system’s resources.

Continue reading How to Backup and Restore (Export and Import) MySQL Databases Tutorial » » »

MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length

July 9th, 2007

When creating a new table or altering an existing table with primary keys, unique constraints and indexes, or when defining a new index with Alter Table manipulation statement in MySQL database, the following error may occur and prohibit the the command from completing:

ERROR 1170 (42000): BLOB/TEXT column ‘field_name’ used in key specification without a key length

Continue reading MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length » » »

Remove or Trim First or Last Few Characters in MySQL Database with SQL

April 23rd, 2007

Another useful string function in MySQL database is TRIM() which will return a text string after removing the matching leading or trailing characters, also known as prefixes or suffixes. It’s been described by MySQL reference as function that returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed.

Continue reading Remove or Trim First or Last Few Characters in MySQL Database with SQL » » »

How to Find and Replace Text in MySQL Database using SQL

April 23rd, 2007

MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake.

Continue reading How to Find and Replace Text in MySQL Database using SQL » » »

How to Escape Characters in Oracle PL/SQL Queries

March 24th, 2007

Oracle databases reserve some special characters with specific meaning and purpose within Oracle environment. These reserved characters include _ (underscore) wild card character which used to match exactly one character, % (percentage) which used to match zero or more occurrences of any characters and ‘ (apostrophe or quotation mark) which used to mark the value supplied. These special characters will not be interpreted literally when building SQL query in Oracle, and may caused error in results returned especially when performing string search with LIKE keyword. To use these characters so that Oracle can interpret them literally as a part of string value instead of preset mean, escape character has to be assigned.

Continue reading How to Escape Characters in Oracle PL/SQL Queries » » »

Easily Duplicate, Copy or Backup Tables in Oracle, PostgreSQL, DB2 and SQLite with Create Table As SQL

March 18th, 2007

In Oracle, PostgreSQL, DB2 and SQLite database system, there is a nice command feature called Create Table As which allows easy duplicating of a table with data from another or a few other tables. The SQL command can also be used to ‘copy and paste’ a table exactly or backup a table data before performing data manipulation query on the original table, just in case the script has error and the backup date can be used to restore to original state. Create Table As will creates a new table built from the content of dataset or result set retrieved by a Select SQL query from a table that already exists within the database.

Continue reading Easily Duplicate, Copy or Backup Tables in Oracle, PostgreSQL, DB2 and SQLite with Create Table As SQL » » »

Change or Set MySQL Long Query Time Value for log-slow-queries

January 23rd, 2007

If you enable slow queries log of MySQL database server, you will notice that from the slow query log file contains only SQL statements and queries that took more than query_time of 10 seconds to execute or run. This is the default value or query time threshold for log_slow_queries function, which is 10 seconds. 10 seconds is way too long for a SQL query to complete, so the value may be too high to capture any meaningful data. You can alter or change the slow query time to lower value or number of seconds.

Continue reading Change or Set MySQL Long Query Time Value for log-slow-queries » » »

Enable Logging of Slow Queries (Slow Query Log) in MySQL Database

January 22nd, 2007

One of the main requirements for a fast web server is to has efficient and effective SQL statements or queries that are optimized. Any non-optimal SQL (Structured Query Language) commands or statements that take too long or lengthy time to execute will use up a lot of system resources, causing MySQL database to run slower, and then more and more queries backlogs queuing up, and when connection limit is reached, visitors are been denied or refused connection. In worst case scenario, your web server will go down as well, or continuously underperform. The case is especially true when you are using MyISAM table type which uses table-level locking instead of row-level locking in a high traffic website.

Continue reading Enable Logging of Slow Queries (Slow Query Log) in MySQL Database » » »