티스토리 뷰

카테고리 없음

mariadb 명령어

렁허 2017. 1. 12. 22:59
[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)


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


mysql -u username -p -h host databasename 


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

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


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

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


[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)



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


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)


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/04   »
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
글 보관함