MYSQL - lukaseriksson/wsp1-mysql GitHub Wiki

My SQL Starta alltid med att starta om apache2 med

sudo service mysql restart

sudo service apache2 restart

Skapa en ny user grant all privileges on . to 'username'@'localhost' identified by 'password'

Baskod

show database/table;

create -- || --;

use database;

describe table;

insert into 'tablename' (fält) values (värde);

SELECT fält(*) from 'tablename'

Kod

**show** database; - Shows all databases

**create** database 'databasename'; - Creates new database

**use** 'databasename'; - Uses database

**show** tables; - Shows all tables

**create** table 'tablename' (id int unsigneg auto_increment, primary key(id)) engine=innodb; - Creates new table and 1 collumn

**select** * from 'tablename' - Selects everything inside table

**alter** table 'tablename' add body varchar(255) not null; - Alter and add string to table

**describe** 'tablename'; - Shows what is in the table

**alter** table 'tablename' add created_at timestamp NULL, add updated_at timestamp NULL; - Add timestamp created_at 
 and updated_at

**insert** into 'tablename' (body, created_at, updated_at, author) values ("", now(), now(), ""); -insert multiple into table