Tag: Debian

  • Create A New MYSQL Database and User

    Here is a quick guide to creating a new MYSQL database, adding a user, and then finally a simple table. I will be using debian/ubuntu as the host system.

    First create the database.

    sudo mysqladmin create testdatabase

    Login as the root user.

    sudo mysql -u root

    Create the database user.

    CREATE USER `test_user`@`localhost` IDENTIFIED BY 'password';

    Now grant the new user permissions on the new database.

    GRANT ALL ON testdatabase.* to `test_user`@`localhost`;

    Don’t forget to flush privileges!

    FLUSH PRIVILEGES;

    Now login to your new user/database.

    mysql -u test_user -p testdatabase

    Now we can create a test table.

    CREATE TABLE `members` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` tinytext COLLATE utf8mb4_unicode_ci NOT NULL,
      `description` text COLLATE utf8mb4_unicode_ci NOT NULL,
      `address` text COLLATE utf8mb4_unicode_ci NOT NULL,
      `url` text COLLATE utf8mb4_unicode_ci NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

    Lets get the description of the table to make sure it worked.

    mysql> desc members;
    +-------------+----------+------+-----+---------+----------------+
    | Field       | Type     | Null | Key | Default | Extra          |
    +-------------+----------+------+-----+---------+----------------+
    | id          | int      | NO   | PRI | NULL    | auto_increment |
    | name        | tinytext | NO   |     | NULL    |                |
    | description | text     | NO   |     | NULL    |                |
    | address     | text     | NO   |     | NULL    |                |
    | url         | text     | NO   |     | NULL    |                |
    +-------------+----------+------+-----+---------+----------------+
    5 rows in set (0.00 sec)
    
    mysql> 
    

    Finally, lets add a quick row.

    mysql> INSERT INTO members(name, description, address, url) VALUES('Matt', 'Hackerman', '1234 Main St.','https://pghcpc.com');
    Query OK, 1 row affected (0.01 sec)

    Run a select query now to show your new row.

    mysql> select * from members;
    +----+------+-------------+---------------+--------------------+
    | id | name | description | address       | url                |
    +----+------+-------------+---------------+--------------------+
    |  1 | Matt | Hackerman   | 1234 Main St. | https://pghcpc.com |
    +----+------+-------------+---------------+--------------------+
    1 row in set (0.00 sec)
    

    That’s it! Have fun with your new database!

  • Change Timezone on Raspian / Debian / Ubuntu

    Here’s a quick and easy way to change the timezone configuration on Raspian / Debian / Ubuntu server, but will probably work on other linux flavors as well.

    First, lets see what our current configuration is:

    timedatectl 
                   Local time: Fri 2021-09-10 19:13:06 BST
               Universal time: Fri 2021-09-10 18:13:06 UTC
                     RTC time: n/a
                    Time zone: Europe/London (BST, +0100)
    System clock synchronized: yes
                  NTP service: active
              RTC in local TZ: no
    

    To get a list of all the supported time-zones:

    timedatectl list-timezones

    And something like this to grep for relevant ones:

    timedatectl list-timezones | grep "America"

    Next, lets set our time-zone:

    sudo timedatectl set-timezone America/New_York

    Finally, check to make sure the changes were applied:

    timedatectl 
                   Local time: Fri 2021-09-10 14:21:42 EDT
               Universal time: Fri 2021-09-10 18:21:42 UTC
                     RTC time: n/a
                    Time zone: America/New_York (EDT, -0400)
    System clock synchronized: yes
                  NTP service: active
              RTC in local TZ: no
    

    That’s it! Pretty simple stuff.