본문 바로가기

Database/MySQL

MySQL 설치 및 샘플 데이터 설치

Reference

아래 사이트를 참조하여 작성한 문서입니다.

 

MySQL 설치

Oracle Linux 7.9 환경에서 테스트한 내용입니다.

yum 명령으로 MySQL을 설치합니다.

[root@demo opc]# yum install mysql-community-server -y
...
Installed:
  mysql-community-server.x86_64 0:8.0.29-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:8.0.29-1.el7                   mysql-community-icu-data-files.x86_64 0:8.0.29-1.el7

Complete!

 

MySQL을 시작하고, 상태를 확인합니다.

[root@demo opc]# systemctl start mysqld
[root@demo opc]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-05-11 01:59:03 GMT; 6s ago
     Docs: man:mysqld(8)
           <http://dev.mysql.com/doc/refman/en/using-systemd.html>
  Process: 23073 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 23249 (mysqld)
   Status: "Server is operational"
    Tasks: 38
   Memory: 465.4M
   CGroup: /system.slice/mysqld.service
           └─23249 /usr/sbin/mysqld

May 11 01:58:59 demo systemd[1]: Starting MySQL Server...
May 11 01:59:03 demo systemd[1]: Started MySQL Server.

초기 설치 시 MySQL root 패스워드가 자동으로 설정되어 있습니다. mysqld.log에서 임시 패스워드를 찾아냅니다.

[root@demo opc]# cat /var/log/mysqld.log | grep 'temporary password'
2022-05-11T01:59:00.474950Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: T0Pghs*JCU5k

 

MySQL에 접속해서 아래와 같이 MySQK root 패스워드를 alter user 명령으로 변경합니다.

[root@demo opc]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 8
Server version: 8.0.29
...
mysql> alter user 'root'@'localhost' identified by 'xxxxxxxxxxxxxx';
Query OK, 0 rows affected (0.01 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29    |
+-----------+
1 row in set (0.00 sec)

mysql> exit
Bye

 

MySQL 샘플 데이터 설치

MySQL 샘플 데이터는 GitHub에서 다운로드 받을 수 있습니다. 아래 GitHub 주소로 이동합니다.

https://github.com/datacharmer/test_db

 

git clone 명령으로도 내려받을 수 있으나, 여기서는 아래와 같이 샘플 데이터 zip 파일을 내려받았습니다.

 

다운로드 받은 zip 파일 형태의 샘플 데이터 MySQL 서버에 업로드합니다.

 

업로드한 샘플 데이터파일의 압축을 해제하고, 해당 디렉토리로 이동합니다.

[root@demo opc]# unzip ./test_db-master.zip
...
inflating: test_db-master/test_versions.sh
[root@demo opc]# cd test_db-master/

 

employees.sql 파일을 열어서InnoDB, MyISAM, Falcon, PBXT, Maria 등의 스토리지 엔진을 아래와 같이 지정할 수도 있으나, 디폴트로 InnoDB 엔진이 활성화되어 있습니다. 따라서 별도로 스토리지 엔진을 지정하지 않았습니다.

set storage_engine = InnoDB;
-- set storage_engine = MyISAM;
-- set storage_engine = Falcon;
-- set storage_engine = PBXT;
-- set storage_engine = Maria;

 

MySQL 명령 툴로 MySQL 인스턴스에 데이터를 로드합니다.

[root@demo test_db-master]# mysql -t -uroot -p < employees.sql
Enter password:
+-----------------------------+
| INFO                        |
+-----------------------------+
| CREATING DATABASE STRUCTURE |
+-----------------------------+
+------------------------+
| INFO                   |
+------------------------+
| storage engine: InnoDB |
+------------------------+
+---------------------+
| INFO                |
+---------------------+
| LOADING departments |
+---------------------+
+-------------------+
| INFO              |
+-------------------+
| LOADING employees |
+-------------------+
+------------------+
| INFO             |
+------------------+
| LOADING dept_emp |
+------------------+
+----------------------+
| INFO                 |
+----------------------+
| LOADING dept_manager |
+----------------------+
+----------------+
| INFO           |
+----------------+
| LOADING titles |
+----------------+
+------------------+
| INFO             |
+------------------+
| LOADING salaries |
+------------------+
+---------------------+
| data_load_time_diff |
+---------------------+
| 00:00:33            |
+---------------------+

 

업로드한 데이터를 확인합니다.

[root@demo test_db-master]# mysql -t -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 13
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| employees          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use employees;
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
mysql> show tables;
+----------------------+
| Tables_in_employees  |
+----------------------+
| current_dept_emp     |
| departments          |
| dept_emp             |
| dept_emp_latest_date |
| dept_manager         |
| employees            |
| salaries             |
| titles               |
+----------------------+
8 rows in set (0.00 sec)

mysql> select count(*) from employees;
+----------+
| count(*) |
+----------+
|   300024 |
+----------+
1 row in set (0.01 sec)

mysql> exit
Bye

<END>

'Database > MySQL' 카테고리의 다른 글

MySQL 연결 Python 코드 샘플  (0) 2022.05.13