Configure mysql server on ubuntu


Why

I installed mysql in the previous post. Now I need to setup users, create a db, and create a table.

Parts of this series

  1. part 1
  2. part 2
  3. part 3

MYSQL Resources

Create a new user

Login as Root


mysql -u root -p

Create some users

In my case I will create 4 users accounts.

  1. Cobra@localhost
  2. Cobra@jnapolitano.com
  3. admin@localhost
  4. dummy@localhost

dummy is just used to test service connection and has not access grants or writes


CREATE USER 'cobra'@'localhost'
  IDENTIFIED BY 'password';
GRANT ALL
  ON *.*
  TO 'cobra'@'localhost'
  WITH GRANT OPTION;

 

CREATE USER 'admin'@'localhost'
  IDENTIFIED BY 'password';
GRANT RELOAD,PROCESS
  ON *.*
  TO 'admin'@'localhost';

CREATE USER 'dummy'@'localhost';

ACTUALLY enter a password above. Do not use password as the user password'

Logout of root

enter EXIT in terminal

Login as your user

In my case I pass mysql -u cobra -p back to the terminal.

Create a DB

I will create a db for my personal website. The first command to run is


CREATE DATABASE jnapolitano;

Use your new db


USE jnapolitano;

Create the posts table


CREATE TABLE posts
(
  id                    BINARY(16) NOT NULL DEFAULT (UUID_TO_BIN(UUID())),  # Unique ID for the record. This a smallish and not a very high performance db this should be fine. 
  author                BINARY(16),                                         # id of author
  publish_date          DATE,                                               # publish date
  description           VARCHAR(150),                                       # post description
  link                  VARCHAR(150),                                       # Link to post
  title                 VARCHAR(150),                                       # title of hte post
  PRIMARY KEY           (id)                                                # Make the id the primary key
);

Create the authors table


CREATE TABLE authors
(
  id                    BINARY(16) NOT NULL DEFAULT (UUID_TO_BIN(UUID())),  # Unique ID for the record. This a smallish and not a very high performance db this should be fine. 
  name                  VARCHAR(150),                                      # name of author
  PRIMARY KEY           (id)                                                # Make the id the primary key
);

Create the mastodon post table

I will be adding support for other systems. I am starting with mastodon.


CREATE TABLE mastodon_posts
(
  id                    BINARY(16) NOT NULL DEFAULT (UUID_TO_BIN(UUID())),  # Unique ID for the record. This a smallish and not a very high performance db this should be fine. 
  post_id               BINARY(16),                                         # name of author
  mastodon_post         VARCHAR(150),                                       # THE POST ID.. if it returns
  PRIMARY KEY           (id)                                                # Make the id the primary key
);