Andrew McDonough

Please note: This page is imported from my wiki, which hasn't been updated in over 10 years. Some of the formatting was lost during the import. I'll try to get around to fixing it someday.

MySQL

SQL

Creating a table

CREATE TABLE sometable ( id int(11) NOT NULL auto_increment, name varchar(40) default NULL, active enum(‘Yes’,‘No’) default NULL, PRIMARY KEY (id) ) TYPE=MyISAM;

Admin

Starting

To start MySQL, run the mysql daemon, mysqld_safe e.g.

”/usr/local/mysql-standard-4.0.20-pc-linux-i686/bin/mysqld_safe &”

Sometimes (e.g. on Kellis) you need to specify where the data files are held:

<PATHTOMYSQL>/mysqld_safe —datadir=/usr/local/var/lib/mysql

Monitoring

You can see what connections MySQL has open by running: mysql-standard-4.0.21-pc-linux-i686]# bin/mysqladmin processlist -p

Adding a user

GRANT ALL PRIVILEGES ON dbname.* TO ‘username’@‘localhost’ IDENTIFIED BY ‘password’

SQL Reference

Mathematic Functions

POW(X,Y) \ POWER(X,Y) \ SQRT(X)

MOD(N,M) \ N % M \ N MOD M

RAND() \ RAND(N)

Resetting Auto Increment

ALTER TABLE AUTO_INCREMENT= ;


Andrew McDonough

Andrew McDonough is a consultant CTO and software developer, currently based between Berlin and London.

Follow Andrew on Twitter or Connect on LinkedIn