Archive

Posts Tagged ‘MySQL’

Auto-incremented fields in apache’s derby

June 27th, 2011 No comments

Unlike MySQL and other SQL dialects, apache derby doesn’t support the AUTO_INCREMENT keyword. To create an auto incremented filed in derby, you can use

CREATE TABLE customer
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
name VARCHAR(40) NOT NULL,
address VARCHAR(1024),
city VARCHAR(30),
CONSTRAINT primary_key PRIMARY KEY (id)
) ;

The value of id is now incremented automagically on every insert. You don’t have to specify it manually in the insert command

INSERT INTO customer(name , address, city)
   VALUES('Mr. Peanutbutter', '221 W 31st St', New York City);

For instruction on how to create auto incremented fields in other SQL dialects, have a look at the SQL Dialects Reference.

Categories: Uncategorized Tags: ,

Resetting MySQL root password

October 13th, 2009 No comments

It shouldn’t happen, but it does: I forgot my MySQL root password. Resetting is rather simple:

mysql --user=root
update mysql.user set Password=PASSWORD('your_new_root_password') where User='root';
flush privileges;
quit;

Don’t forget to clear ~/.mysql_history afterwards!

Categories: Uncategorized Tags: