리눅스 MariaDB 설치 및 초기 접속, DB 생성부터 테이블 생성까지
반응형
1. MariaDB 설치
아래 명령을 실행한다. 패키지명의 대소문자에 주의해야한다.
[root@localhost ~]# yum -y install mariadb-server mariadb-client
2. MariaDB 서비스 실행
아래 명령으로 MariaDB 서비스 실행
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled
Active: active (running) since 화 2019-12-24 13:58:33 KST; 29s ago
Process: 2391 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0
Process: 2304 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SU
Main PID: 2390 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─2390 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─2552 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/u
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: MySQL manual for more in
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: Please report any proble
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: The latest information a
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: You can find additional
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: http://dev.mysql.com
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: Consider joining MariaDB
12월 24 13:58:31 localhost.localdomain mariadb-prepare-db-dir[2304]: https://mariadb.org/get-
12월 24 13:58:31 localhost.localdomain mysqld_safe[2390]: 191224 13:58:31 mysqld_safe Logging
12월 24 13:58:31 localhost.localdomain mysqld_safe[2390]: 191224 13:58:31 mysqld_safe Startin
12월 24 13:58:33 localhost.localdomain systemd[1]: Started MariaDB database server.
3. 보안 설정
몇 단계에 걸쳐 보안 설정을 마치게 되면 root로 접속이 가능하게 된다.
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
-- 현재 비밀번호 입력하라 (최초 접속이므로 비밀번호가 없으니 "Enter" 누른다)
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
-- root 패스워드 설정 여부 "Y"
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
-- 익명 사용자의 삭제 여부 "Y"
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
-- root 계정의 외부 접속을 허용할 것인가 "Y"
Disallow root login remotely? [Y/n] Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
-- 기본적으로 생성되는 test 데이터베이스를 삭제할 것이가 "Y"
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
-- 현재까지 설정한 것을 즉시 적용할 것인가 "Y"
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
4. MariaDB 자동 실행
부팅시 mariadb를 자동 실행 하려면 아래의 명령어를 실행한다.
[root@localhost ~]# systemctl enable mariadb
5. MariaDB 접속
# mysql -u root -p 명령어로 접속
[root@localhost ~]# mysql -u root -p
Enter password: 비밀번호 입력
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.64-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)]>
6. MariaDB Database 조회 및 생성
- Database 조회 명령어 : show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
- Database 생성 명령어 : CREATE DATABASE DB명;
MariaDB [(none)]> CREATE DATABASE test;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
7. Table 조회 및 생성
-- 테이블 조회하기 전 사용할 Database 선택
MariaDB [(none)]> use test;
Database changed
-- 테이블 조회
MariaDB [test]> show tables;
Empty set (0.00 sec)
-- 테이블 생성
MariaDB [test]> CREATE TABLE test_table (name nvarchar(30), dept nvarchar(30), Email nvarchar(30)); Query OK, 0 rows affected (0.02 sec)
-- 테이블 생성 확인
MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test_table |
+----------------+
1 row in set (0.00 sec)
8. 데이터 삽입 및 조회
-- 데이터 삽입
MariaDB [test]> INSERT INTO test_table VALUES ('홍길동', '경영관리팀', 'aaaaa@naver.com');
Query OK, 1 row affected (0.01 sec)
-- 데이터 조회
MariaDB [test]> SELECT * FROM test_table;
+-----------+-----------------+-----------------+
| name | dept | Email |
+-----------+-----------------+-----------------+
| 홍길동 | 경영관리팀 | aaaaa@naver.com |
+-----------+-----------------+-----------------+
1 row in set (0.00 sec)
반응형
'IT > Linux' 카테고리의 다른 글
리눅스 네임서버 존 추가하기 (0) | 2020.01.30 |
---|---|
CENTOS 7 에서 MySQL Select 하여 결과 값을 SMTP 메일 보내기 (0) | 2020.01.03 |
리눅스 메일서버의 SMTP를 사용한 메일전송 (0) | 2019.12.20 |
리눅스 yum groupinstall 명령어 오류 - no packages in any requested group available to install or update (2) | 2019.12.20 |
CentOS 초기 설치 후 설정 및 네트워크 설정하기 (0) | 2019.12.20 |
댓글