Archive for the ‘Mysql’ Category

Mysql: Java Web App and MySql 5.x UTF-8

Saturday, November 8th, 2008

To fully support UTF-8 with mysql, make sure of the followings:

  1. Set HttpServletRequest UTF-8 character encoding.
    request.setCharacterEncoding(”UTF-8″);
  2. Set HttpServletResponse UTF-8 character encoding
    response.setContentType(”text/html; charset=UTF-8″);
  3. Create the Column, Table, or DB need to have the UTF8 charset and collation
    CHARACTER SET utf8 COLLATE utf8_general_ci
  4. THE TRICK: Add the character encoding instruction in your JDBC URL
    jdbc:mysql://localhost:3306/DATABASENAME?useUnicode=true&characterEncoding=UTF8

Related links:

Mysql: Create Foreign Key

Sunday, October 12th, 2008

Assuming 1 to M from Person to Address:

ALTER TABLE address ADD
CONSTRAINT FK_address_person_id
FOREIGN KEY (person_id)
REFERENCES person(id) ON DELETE CASCADE

MySQL - SQL Table Basics - Table Relationships

Mysql: Create new user

Wednesday, October 1st, 2008

Create a new user:

grant all privileges on YourDatabase.* to UserName@localhost identified by ‘Password’ with grant option;

Mysql: Create Database

Wednesday, October 1st, 2008

Create a new Database:

create database YourTableName character set utf8 collate utf8_general_ci