All about

mariadb를 실행합니다.

root@MacBookAir var % mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.7.3-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]>

현재 db 현황을 확인합니다.

MariaDB [(none)]> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
| test        |
+--------------------+
5 rows in set (0.001 sec)

test_db를 생성합니다.

MariaDB [none]> create database test_db;
Query OK, 1 row affected (0.001 sec)

test_db를 사용합니다.

MariaDB [none]> use test_db;
Database changed

계정을 생성합니다. 이때 명령어는"create user {user name}@localhost identified by '{password}';" 인데, localhost에서만 접속한다면 localhost로, 어디서든 접속을 한다면 '%'를 사용합니다.

MariaDB [test_db]> create user root@localhost identified by ‘root’;
Query OK, 0 rows affected (0.022 sec)

종종 예제코드를 따라할 때 "ERROR 1396 (HY000): Operation CREATE USER failed for ‘root’@‘localhost’" 같은 에러를 겪는 경우가 있는데, 예제를 반복해보다가 이미 있는 계정을 생성하기 때문에 발생하는 문제입니다. 이 경우 아래와 같은 명령어를 통해 해결할 수 있습니다.

MariaDB [test_db]> delete from mysql.db where User =‘root’;
Query OK, 0 rows affected (0.001 sec)
MariaDB [test_db]> delete from mysql.user where User =‘root’;
Query OK, 1 row affected (0.023 sec)
MariaDB [test_db]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

권한을 부여합니다.

# select 권한만 부여
# grant select on {schema}.{table} to {user_name}@localhost;
MariaDB [test_db]> grant select on test_db.* to root@localhost;
Query OK, 0 rows affected (0.025 sec)

# 모든 권한 부여
# grant all privileges on {schema}.{table} to root@localhost;
MariaDB [test_db]> grant all privileges on test_db.* to root@localhost;
Query OK, 0 rows affected (0.021 sec)

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading