Thursday, November 2, 2017

MySQL Command-Line Tool: tutorial

  1. SHOW DATABASES;
  2. CREATE DATABASE pets;
  3. USE pets;
  4. SHOW TABLES;
  5. CREATE TABLE cats
    (
      id              INT unsigned NOT NULL AUTO_INCREMENT, # Unique ID for the record
      name            VARCHAR(150) NOT NULL,                # Name of the cat
      owner           VARCHAR(150) NOT NULL,                # Owner of the cat
      birth           DATE NOT NULL,                        # Birthday of the cat
      PRIMARY KEY     (id)                                  # Make the id the primary key
    );
  6. DESCRIBE cats;
  7. INSERT INTO cats ( name, owner, birth) VALUES
      ( 'Sandy', 'Lennon', '2015-01-03' ),
      ( 'Cookie', 'Casey', '2013-11-13' ),
      ( 'Charlie', 'River', '2016-05-21' );
  8. SHOW CREATE TABLE cats\G;
  9. SELECT * FROM cats;
    SELECT name FROM cats WHERE owner = 'Casey';
  10. DELETE FROM cats WHERE name='Cookie';
  11. ALTER TABLE cats ADD gender CHAR(1) AFTER name;
  12. ALTER TABLE cats DROP gender;
  13. tee /link/to/outputfile;

No comments:

Post a Comment