---
# System prepended metadata

title: How to Use MySQL
tags: [' database', computer science]

---

---
tags: computer science, database
---

# How to Use MySQL

> 本文件將紀錄安裝與使用MySQL的過程，並進一步作為Java Programming 2的教材。

:::info
MySQL is an essential component of the LAMP stack, which includes Linux, Apache, MySQL, and PHP.
:::

:::danger
The official way to pronounce "MySQL" is "My Ess Que Ell" (not "my sequel"), but some do not mind if you pronounce it as "my sequel" or in some other localized way. 
:::

## Installation
- Official website: https://dev.mysql.com/downloads/installer/
    - For windows users, ...
    - For linux users, ...
- Free visual manager of databases: DBeaver https://dbeaver.io/
:::warning
帳號預設root，建議要另外建立一個admin的帳號。
:::
- Dependencies
    - Python https://www.python.org/downloads/
:::warning
為了避免Python最新版和既有的MySQL環境衝突，我先安裝Python 3.7.x在Windows 10系統上。
:::
:::danger
MySQL workbench根本垃圾....
:::

## Quick Start
- Official manual https://downloads.mysql.com/docs/mysql-tutorial-excerpt-5.7-en.pdf#page26
- Lecture slides for basic usage of MySQL http://www.di.uniba.it/~cdamato/corsi/BasiDiDati-Materiale/Intro%20a%20MySQL.pdf

```bash=
# First login
sudo mysql -u root -p

# Create another user
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

# Show all users in MySQL
SELECT User, Host, Password FROM mysql.user;

# Create a new user with all privileges
GRANT ALL PRIVILEGES ON *.* TO 'database_user'@'localhost';
```

- You should add client option to your mysql-connector ==allowPublicKeyRetrieval=true== to allow the client to automatically request the public key from the server. Note that AllowPublicKeyRetrieval=True could allow a malicious proxy to perform a MITM attack to get the plaintext password, so it is False by default and must be explicitly enabled.

- How to Create MySQL Users Accounts and Grant Privileges https://linuxize.com/post/how-to-create-mysql-user-accounts-and-grant-privileges/

### What is a Schema?
- https://www.sqlshack.com/a-walkthrough-of-sql-schema/

### Java Spring Boot
- Accessing data with MySQL https://spring.io/guides/gs/accessing-data-mysql/
- Accessing Data with JPA https://spring.io/guides/gs/accessing-data-jpa/

## MISC

### What is SQL?
- https://en.wikipedia.org/wiki/SQL