Categories
mysql Web optimization

Mysql: increase the size of innodb_buffer_pool_size

By putting this on your mysql config file:

[mysqld]
innodb_buffer_pool_size = 2G

In dedicated db machines, you can set this to close to 80% of the available memory. This will avoid disk writes and speed up things in general.

The mysql configuration file is on :

/etc/my.cnf (usually)

Restaring mysql, and barabum barabim

The typical error message you get when this is too small is:

Mysql::Error: The total number of locks exceeds the lock table size:

Categories
mysql

MySQL example of how to do an insert on a table

INSERT INTO table_name (column1, column2, column3,…)
VALUES (value1, value2, value3,…)

Categories
mysql

MySQL example on how to add a timestamp column to a table

ALTER TABLE [table_name] ADD COLUMN [clumn_name] timestamp with time zone;

Categories
mysql

MySQL example of how to delete a record

DELETE FROM [table_name] where [condition_column]=’blahblah’;

Categories
mysql

MySQL example of granting permission to a user to a given table

GRANT DELETE ON [table_name] TO [user_name];

Categories
mysql

MySQL example of dropping a column

ALTER TABLE pub_agreements DROP COLUMN registration_id;

Categories
mysql

MySQL example of updating a table

UPDATE [table] SET [column_name]=’whatever value’ WHERE name=’Channel AB’

Categories
mysql

MySQL example of how to create a table

CREATE TABLE films ( code char(5) CONSTRAINT firstkey PRIMARY KEY, title varchar(40) NOT NULL, did integer NOT NULL, date_prod date, kind varchar(10), len interval hour to minute, is_boolean boolean );

Categories
mysql

MySQL: example of how to add a column to an existing table

ALTER TABLE lib2lib ADD COLUMN greeting int;

Categories
mysql

MySQL example of using the LIKE operator in queries

select name from channel where name LIKE ‘%CNET%’;

The % matches 0 or more characters, if you want to match only one character, you use _