Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

MySQL DISTINCT with Case Sensitive

Tags: March 14, 2019 9:55 AM
0 comments

Goals

We want MySQL distinct to use case sensitive grouping because by default MySQL use case insensitive.

Solution of MySQL DISTINCT case sensitive

We can use binary operator to convert the character set.

SELECT DISTINCT CAST(expr as BINARY)
As an alternative we can just use BINARY.
SELECT BINARY expr

References

Share on Facebook Twitter

Disable Word Wrap on MySQL Shell

Tags: March 8, 2019 8:54 PM
0 comments

Goals

Turn off or disable word wrap on MySQL shell

Solution of Disable Word Wrap on MySQL Shell

We can use external pager such as less to do the job. Pager in MySQL shell actually is a pipe to another program.

mysql> pager less -SFX
PAGER set to 'less -SFX'

That's it. Simple and easy. Now when you have very long output horizontally it will not wrap.

Reference

Share on Facebook Twitter

Reset All Tables Except Migration Table on MySQL

Tags: April 15, 2016 9:29 PM
0 comments

Overview

When developing an application there is case when you need to clear all the data in your database e.g: testing the seeding or such. But you want to exclude some tables let say migration table which used by the application framework to migrate the schema.

Problem

You want to clean up data on all the tables, except the migration table because you don't want to re-run the schema migration.

Solution

  1. Get list of tables
  2. Exclude the migration table
  3. Append the prefix 'DELETE FROM ' to each line
  4. Append the suffix ';' to each line
  5. Pipe the result to MySQL
$ echo "SHOW TABLES;" | mysql -N DB_NAME | grep -v orb_migration | sed -e 's/^/DELETE FROM /' -e 's/$/;/' | mysql DB_NAME
In case above the table which excluded is orb_migration.

Share on Facebook Twitter

How to Fix MySQL Fatal error: Illegal or unknown default time zone

Tags: October 19, 2014 2:36 PM
0 comments

Problem

You want to set the default timezone for MySQL using my.cnf configuration file. But MySQL unable to start and the error log says:

Fatal error: Illegal or unknown default time zone 'NAMED_TIMEZONE'

Solution

Do not use named timezone unless you had timezone data populated on your mysql database. Instead use an offset relative to the UTC e.g: '+07:00' or '-04:00'.

Share on Facebook Twitter

MySQL: Updating Table using UPDATE REPLACE Query

Tags: April 29, 2012 9:31 AM
0 comments

This query is quite helpful when you moving from development machine to production where your table content is full of dozen 'http://localhost/' links.

Syntax

UPDATE [table] SET [column] = REPLACE(
  [column],
  [old_value],
  [new_value]
) WHERE [column] LIKE [old_value];

Share on Facebook Twitter

Instalasi Apache PHP MySQL pada Ubuntu Server

Tags: April 28, 2012 12:13 PM
0 comments

PHP.net merekomendasikan penggunan apache-mpm-prefork karena ada beberapa extension PHP yang masih belum thread safe.

## dengan menginstall libapache2-mod-php5 maka otomatis paket-paket apache ikut terinstall
# apt-get install libapache2-mod-php5

## install PHP APC untuk opcode caching
# apt-get install php-apc

## install ekstensi untuk mysql
# apt-get install php5-mysql

## install mysql server
# apt-get install mysql-server

Share on Facebook Twitter