본문 바로가기
✍ 따뜻한 개발 공부

[MySQL] 백엔드도 재밌엉 >_< MySQL 깔짝여보기 / Express , postman 만져보기

by 따따시 2023. 1. 11.

 

 

Last login: Wed Jan 11 20:27:38 on ttys004
➜  ~ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>
mysql> create user hong@localhost identified by '12345';
Query OK, 0 rows affected (0.01 sec)

mysql> select * from user;
ERROR 1046 (3D000): No database selected
mysql> select * from mysql.user;
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------------------+--------------------------+----------------------------+---------------+-------------+-----------------+----------------------+-----------------------+------------------------------------------------------------------------+------------------+-----------------------+-------------------+----------------+------------------+----------------+------------------------+---------------------+--------------------------+-----------------+
| Host      | User             | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher             | x509_issuer              | x509_subject               | max_questions | max_updates | max_connections | max_user_connections | plugin                | authentication_string                                                  | password_expired | password_last_changed | password_lifetime | account_locked | Create_role_priv | Drop_role_priv | Password_reuse_history | Password_reuse_time | Password_require_current | User_attributes |
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------------------+--------------------------+----------------------------+---------------+-------------+-----------------+----------------------+-----------------------+------------------------------------------------------------------------+------------------+-----------------------+-------------------+----------------+------------------+----------------+------------------------+---------------------+--------------------------+-----------------+
| localhost | hong             | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          | 0x                     | 0x                       | 0x                         |             0 |           0 |               0 |                    0 | caching_sha2_password | $A$005$@8R.2}R{     	1@r
                                                                                                                   k5k1ptm29hyfisSooIIsnhXgqEc.t4LJCiYSKZT9DMs8 | N                | 2023-01-11 20:32:56   |              NULL | N              | N                | N              |                   NULL |                NULL | NULL                     | NULL            |
| localhost | mysql.infoschema | Y           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          | 0x                     | 0x                       | 0x                         |             0 |           0 |               0 |                    0 | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | N                | 2023-01-11 20:29:27   |              NULL | Y              | N                | N              |                   NULL |                NULL | NULL                     | NULL            |
| localhost | mysql.session    | N           | N           | N           | N           | N           | N         | N           | Y             | N            | N         | N          | N               | N          | N          | N            | Y          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          | 0x                     | 0x                       | 0x                         |             0 |           0 |               0 |                    0 | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | N                | 2023-01-11 20:29:27   |              NULL | Y              | N                | N              |                   NULL |                NULL | NULL                     | NULL            |
| localhost | mysql.sys        | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          | 0x                     | 0x                       | 0x                         |             0 |           0 |               0 |                    0 | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | N                | 2023-01-11 20:29:27   |              NULL | Y              | N                | N              |                   NULL |                NULL | NULL                     | NULL            |
| localhost | root             | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          | 0x                     | 0x                       | 0x                         |             0 |           0 |               0 |                    0 | caching_sha2_password |                                                                        | N                | 2023-01-11 20:29:27   |              NULL | N              | Y                | Y              |                   NULL |                NULL | NULL                     | NULL            |
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------------------+--------------------------+----------------------------+---------------+-------------+-----------------+----------------------+-----------------------+------------------------------------------------------------------------+------------------+-----------------------+-------------------+----------------+------------------+----------------+------------------------+---------------------+--------------------------+-----------------+
5 rows in set (0.00 sec)

mysql> exit;
Bye
➜  ~ mysql -u hong -p;
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.31 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
2 rows in set (0.01 sec)

mysql> create database hongbase;
ERROR 1044 (42000): Access denied for user 'hong'@'localhost' to database 'hongbase'
mysql> exit;
Bye
➜  ~ mysql -u root;
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.31 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database hongbase;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON hongbase.* TO hong@localhost IDENTIFIED BY '12345';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '12345'' at line 1
mysql>  GRANT ALL PRIVILEGES ON hongbase.* TO hong@localhost IDENTIFIED;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED' at line 1
mysql> GRANT ALL PRIVILEGES ON hongbase.* TO hong@localhost;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
➜  ~ mysql -u hong -p;
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.31 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| hongbase           |
| information_schema |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> use hongbase;
Database changed
mysql> select * from hongbase;
ERROR 1146 (42S02): Table 'hongbase.hongbase' doesn't exist
mysql> create table users(
    ->     name varchar(255),
    -> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3
mysql> create table users(
    ->     name varchar(255),
    -> )
    ->
    -> create table users(
    ->     name varchar(255),
    ->     name varchar(
    ->
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')

create table users(
    name varchar(255),
    name varchar(' at line 3
mysql> create table users(
    ->     name varchar(255)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+-----------------------+
| Tables_in_데이터베이스이름|
+-----------------------+
| users                 |
+-----------------------+
1 row in set (0.00 sec)

mysql> insert into users (name) values ('내가쓰고싶은벨류');
Query OK, 1 row affected (0.00 sec)

mysql> select * from users;
+----------+
| name     |
+----------+
| 내가쓰고싶은밸류 |
+----------+
1 row in set (0.00 sec)

 

 

요건 오라클 디벨로퍼같은 넘인듯하다 ㅎ.ㅎ (cask는 GUI를 커맨드로 설치할 수 있게 해주는 용어라고 하셧당 )

➜ ~ brew install --cask sequel-ace

 

아무튼 요놈 설치해주고 로그인해주깅

 

 

 

 

그리고 요 postman이라는 넘도 써서 아래 만들어놓았던 코드들을 실행해보면서 express를 직접 사용해봐땅>_<

 

 

 

 

 

요건 app.js 폴더

import express from "express";
import { todosRoute } from "./route/todos.js";
const app = express();
const port = 8080;

//라우터를 사용해서 todos로 오는 요청들은 todosRoute로 보내주는 것
app.use(express.json());
app.use("/todos", [todosRoute]);

// '/'로 서버에 요청을해서 response로 받아왔음 아래 json정보를
app.get("/", (req, res) => {
  res.json({ jsonst: "jsonnnnsssss" });
});

// port 8080으로 들어오는 요청을 듣고있음
// 들었으면, 콘솔창 찍히는것
app.listen(port, () => {
  console.log(port, "포트로 서버가 열렸어요!");
});

 

요건 라우터 폴더 만든고 ㅇㅅㅇ

import express from "express";

// 라우터가 생성됌
export const todosRoute = express.Router();

//response에 제이슨 데이터 넘겨주고있음
todosRoute.get("/", (req, res) => {
  res.json({ routesssss: "get쩔엉" });
});

//작업즁
todosRoute.post("/", (req, res) => {
  //body : request의 속성임
  console.log("req.body.name:", req.body.name);
  res.json({ routesssss: "post쩔엉~~~" });
});

댓글