Skip to content

Create a MySQL database, table and some records

FiveTech Software edited this page Jun 12, 2020 · 6 revisions
  1. Install MariaDB:
sudo apt install mariadb-server
  1. run: mysqld

  2. /etc/init.d/mysql start

From Linux or OSX:

sudo mysql -u root -p 

from Windows:

c:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p  

CREATE DATABASE dbHarbour;

USE dbHarbour;

CREATE TABLE users (name VARCHAR(30), age INT);

DESCRIBE users;

INSERT INTO users VALUES ('Homer Simpson', 52);

INSERT INTO users VALUES ('Peter Pan', 45);

SELECT * FROM users;


Create a user named 'harbour':

mysql> CREATE USER 'harbour'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

or

mysql> CREATE USER 'harbour'@'localhost' IDENTIFIED WITH mysql_native_password;
mysql> GRANT ALL PRIVILEGES ON dbHarbour.* TO'harbour'@'localhost';
update mysql.user SET Password=PASSWORD('password') WHERE User='harbour';
flush privileges;

Check existing MySQL users:

SELECT User FROM mysql.user;