본문 바로가기

카테고리 없음

MariaDB 셋팅 방법 (접속, 디비생성, 권한부여, 외부접속)

http://ora-sysdba.tistory.com/entry/MariaDB-Maria-DB-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EC%83%9D%EC%84%B1-%EA%B6%8C%ED%95%9C-%EB%B6%80%EC%97%AC-%EC%A0%91%EC%86%8D


Create Maria Database

아래와 같은 방법으로 데이터베이스를 생성합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[root@sys4u ~]# /usr/local/mysql/bin/mysql
Welcome to the MariaDB monitor.  Commands end with or \g.
Your MariaDB connection id is 3
Server version: 5.5.30-MariaDB-log Source distribution
 
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> use mysql
Database changed
 
MariaDB [mysql]> create database orademo;
Query OK, 1 row affected (0.00 sec)
 
-- User를 생성하고 권한을 부여합니다.
MariaDB [orademo]> create user 'ecsees'@'localhost' identified by 'xxxxx';
Query OK, 0 rows affected (0.00 sec)
 
-- 혹시라도 외부에서 접속하려면 localhost가 아닌 '%'로 추가 생성하여야 합니다.
MariaDB [orademo]> grant all privileges on orademo.* to ecsees@localhost;
Query OK, 0 rows affected (0.00 sec)
 
-- 확인합니다.
MariaDB [orademo]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [orademo]> exit
Bye
 
[root@sys4u ~]# /usr/local/mysql/bin/mysql -u ecsees -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with or \g.
Your MariaDB connection id is 9
Server version: 5.5.30-MariaDB-log Source distribution
 
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> show databases;
+--------------------+
Database           |
+--------------------+
| information_schema |
| orademo            |
| test               |
+--------------------+
rows in set (0.01 sec)


Maria DB Connection

데이터베이스에 접속하기 위하여 다음의 명령을 입력하여 접속합니다.

1
mysql -u username -p -h host databasename 
username : 접속하고자 하는 데이터베이스 사용자명으로 변경 
host : 데이터베이스 서버를 위한 URI로 변경 (데이터베이스가 로컬 호스트에 존재하는 경우 'localhost'를 입력하면 됩니다.) 

databasename : 접속하고자 하는 데이터베이스명으로 변경 (암호를 물어 보는 경우 암호를 입력하면 됩니다.)


-h host 옵션을 생략하는 경우 로컬 호스트를 의미합니다.

-u username 옵션을 생략하는 경우 현재 서버에 로그인한 사용자 이름을 의미합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@sys4u ~]# /usr/local/mysql/bin/mysql -u ecsees -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.30-MariaDB-log Source distribution
 
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| orademo            |
test               |
+--------------------+
3 rows in set (0.01 sec)


Maria DB Authorization

아래와 같은 방법으로 해당 유저에 권한을 부여합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
MariaDB [mysql]> select host, userpassword from user;
+-------------+------+----------+
| host        | user password |
+-------------+------+----------+
| localhost   | root |          |
| sys4u.co.kr | root |          |
| 127.0.0.1   | root |          |
| ::1         | root |          |
| localhost   |      |          |
| sys4u.co.kr |      |          |
+-------------+------+----------+
rows in set (0.00 sec)
 
MariaDB [mysql]> grant all privileges on *.* to 'root'@'%' identified by 'xxxx';
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [mysql]> select host, userpassword from user;
+-------------+------+-------------------------------------------+
| host        | user password                                  |
+-------------+------+-------------------------------------------+
| localhost   | root |                                           |
| sys4u.co.kr | root |                                           |
| 127.0.0.1   | root |                                           |
| ::1         | root |                                           |
| localhost   |      |                                           |
| sys4u.co.kr |      |                                           |
| %           | root | *7CFE0F9598C6E65BA068ADFDA6162087820AEAD7 |
+-------------+------+-------------------------------------------+
rows in set (0.00 sec)
 
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.01 sec)