Categories
mysql

MySQL: run it from a file

mysql -u whoever -p database_name_here < sql_file_here.sql

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 PHP

Extension not found error when trying to run the DB package for php Pear

This only means you did not configure that specific database to be compiled with php. For example, if you get that error when trying to connect to a mysql database, make sure that when you run ./configure (when installing php) you included the -with–mysql option.

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 );