jas0nhuang

MySQL on Linux (1)

(COURSERA: Using Databases with Python)

0. INTRO

C(I) R(S) U D
SCHEMA(META-DATA)

1. Instalation

dnf update
dnf install @mysql

2. Start MySQL service

sudo systemctl start mysqld
sudo systemctl status mysqld

secure the database

mysql_secure_installation

follow the setup process.

3. Using MySQL

Start up MySQL interface:

mysql -u USERNAME -p

Some Basic Operations and Single Table CRUD:

mysql> SHOW DATABASES;
mysql> CREATE DATABASE XXX;
mysql> USE XXX
mysql> CREATE TABLE YYY

Create table with colums and data info.

mysql> CREATE TABLE YYY(
name VARCHAR(128),
email VARCHAR(128)
);

Insert data into a table:

INSERT INTO YYY (name, email) VALUES ('MyNAME', 'My@EMAIL.COM')

Delete data from a table:

DELETE FROM YYY WHERE email='My@EMAIL.COM'

Update data in a table:

UPDATE YYY SET name='MyNAME' WHERE email='My@EMAIL.COM'

Select(Read):

SELECT * FROM YYY
SELECT * FROM YYY WHERE email='My@EMAIL.COM'
SELECT * FROM YYY ORDER BY name

Delete Table:

DROP TABLE YYY

Delet database:

DROP DATABASE XXX