Monday, November 25, 2019

mySQL: the basic that I always forget

Connect to the DB:
mysql -h hote -u utilisateur -p


SELECT VERSION(),CURRENT_DATE;

Then you can make some calculations:
SELECT SIN(PI()/4), (4+1)*5;

Creation of a database:
CREATE DATABASE menagerie;

Use it:
USE menagerie;

Connect you to the DB-server and specify the DB you are interested in:
mysql -h hote -u utilisateur -p menagerie
SHOW TABLES;
CREATE TABLE animal (nom VARCHAR(20), maitre VARCHAR(20),
espece VARCHAR(20), sexe CHAR(1), naissance DATE, mort DATE);
DESCRIBE animal;
LOAD DATA LOCAL INFILE "animal.txt" INTO TABLE animal;
INSERT INTO animal VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);