Infra & Devops/Linux
[Linux / CentOS 7] MariaDB 설치하기
겸둥이xz
2021. 8. 24. 23:03
반응형
1. MariaDB 설치하기
- yum -y install mariadb-server
[root@server1 ~]# yum -y install mariadb-server
...
...
Installed:
mariadb-server.x86_64 1:5.5.68-1.el7
Dependency Installed:
mariadb.x86_64 1:5.5.68-1.el7 mariadb-libs.x86_64 1:5.5.68-1.el7
perl-DBD-MySQL.x86_64 0:4.023-6.el7
Complete!
2. MariaDB 서비스 실행하기
- systemctl start mariadb
- systemctl enable mariadb
[root@server1 ~]# systemctl start mariadb
[root@server1 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
3. MariaDB 실행하기
- mysql -u root -p
- password는 그냥 Enter 키 입력시 넘어가집니다
[root@server1 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
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)]>
4. 데이터 베이스 선택하기
- SHOW DATABASES;
- USE mysql;
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]>
5. 테이블 목록 보기
- SHOW TABLES;
MariaDB [mysql]> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
6. 계정과 관련된 테이블 보기 (user 테이블)
- SELECT host, user FROM user;
- root 계정만 존재하는 것을 확인할 수 있음
MariaDB [mysql]> SELECT host, user FROM user;
+-----------+------+
| host | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| server1 | |
| server1 | root |
+-----------+------+
6 rows in set (0.00 sec)
다른 가상머신에서 접속해보기
1. test_db 만들기, test 계정 생성하기
- CREATE DATABASE test_db;
- GRANT ALL PRIVILEGES ON test_db.* TO test@'192.168.56.%' IDENTIFIED BY '1234';
- test_db 의 모든 테이블에 접근할 수 있는 test 계정 생성, 비밀번호 1234
MariaDB [mysql]> CREATE DATABASE test_db;
Query OK, 1 row affected (0.00 sec)
MariaDB [mysql]> GRANT ALL PRIVILEGES ON test_db.* TO test@'192.168.56.%' IDENTIFIED BY '1234';
Query OK, 0 rows affected (0.00 sec)
2. 다른 가상머신에서 mariadb 설치하고 실행
- yum -y install mariadb-server
- systemctl start mariadb
- systemctl enable mariadb
[root@server2 ~]# systemctl start mariadb
[root@server2 ~]# systemctl enable mariadb
3. 첫 번째 가상 머신(server1) 에서 server2가 접속 가능하도록 방화벽을 설정합니다
- firewall-cmd --permanent --add-service=mysql
- firewall-cmd --reload
[root@server1 ~]# firewall-cmd --permanent --add-service=mysql
success
[root@server1 ~]# firewall-cmd --reload
success
4. server2에서 test 계정으로 접속을 시도합니다
- mysql -h [server1 주소] -u test -p
- 비밀번호 1234
[root@server2 ~]# mysql -h 192.168.56.10 -u test -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.68-MariaDB MariaDB Server
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)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| test_db |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]>
5. test_db 에 여러가지 작업해보기
반응형