1. Homebrew 를 이용하여 MariaDB 설치
https://mariadb.com/ko/resources/blog/installing-mariadb-10-1-16-on-mac-os-x-with-homebrew/

Installing MariaDB Server on Mac OS X with Homebrew | MariaDB

Developing on your Mac? Get the latest stable MariaDB version on OS X easily with Homebrew. See this step by step guide on installing MariaDB 10.4.13.

mariadb.com


나의 맥북에서는..

//탐색
brew update - brew 정보 업데이트
brew search mariadb 마리아 DB 찾아보기
brew info mariadb 마리아 DB 정보 보기
//설치
brew install mariadb 

c@cgui-MacBookPro ~ % mysql_install_db
mysql.user table already exists!
Run mysql_upgrade, not mysql_install_db

c@cgui-MacBookPro ~ % mysql.server start
Starting MariaDB
. SUCCESS! 

c@cgui-MacBookPro ~ % mysql
MariaDB [(none)]> exit
Bye


2. root 비밀번호 생성 하고 secure-install

c@cgui-MacBookPro ~ % mysql
MariaDB [(none)]> show databases;
MariaDB [(none)]> use mysql;
MariaDB [mysql]> set password for 'root'@'localhost' = PASSWORD(‘비밀번호');
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit

c@cgui-MacBookPro ~ % mysql -u root -p
Enter password: 비밀번호입력

MariaDB [(none)]> exit

c@cgui-MacBookPro ~ % mariadb-secure-installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
      .
      .
      .
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

3. Database, table 만들고 사용자 만들어 권한 주기

// root 로그인
c@cgui-MacBookPro ~ % mysql -u root -p
Enter password: root비밀번호

// create database
MariaDB [(none)]> create database test_db;
Query OK, 1 row affected (0.002 sec)

// use database
MariaDB [(none)]> use test_db;
Database changed

// create table 
MariaDB [test_db]> CREATE TABLE `test_table` (
    ->   `date` text NOT NULL,
    ->   `id` varchar(15) NOT NULL,
    ->   `title` text NOT NULL,
    ->   `desc` text NOT NULL,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.038 sec)

// table 확인
MariaDB [test_db]> show tables;

// ab 라는 user 만들고 비밀번호 생성
MariaDB [test_db]> create user 'ab'@'%' identified by 'ab의 비밀번호';
Query OK, 0 rows affected (0.010 sec)

// user 가 사용할 database에 권한 주기
MariaDB [test_db]> grant all privileges on test_db.* to 'ab'@'%';
Query OK, 0 rows affected (0.011 sec)

MariaDB [test_db]> exit
Bye
// ab 라는 user 로 접근하여 확인해 보기
c@cgui-MacBookPro ~ % mysql -u ab -p
Enter password: ab의 비밀번호

MariaDB [(none)]> use test_db;
Database changed

MariaDB [test_db]> select * from test_table;
Empty set (0.000 sec)

MariaDB [test_db]>

'Mac OS' 카테고리의 다른 글

[macOS] Ventura 단축키 찾아보기  (0) 2022.11.19

분리자를 이용한 파일을 이용하여 데이터를 한번에 편하게 밀어 넣을 수 있는 방법이 있다.

샘플은 data.txt 는 탭으로 분리된 파일이고

하나의 라인은 '\n'으로 구분된다.

컬럼에 대해 별다른 정의가 없으니

테이블에 정의된 컬럼 개수와 순서대로 데이터가 들어갈 것이다.  

 

MariaDB [test_db]> LOAD DATA LOCAL INFILE '/home/data.txt' INTO TABLE test_table FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';

데이터베이스명 : test_db

테이블명 : test_table

 

* primary key 설정

CREATE TABLE `test_table` (
  `id` varchar(15) NOT NULL,
  `title` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

*데이터 삽입 중복키 발생시 업데이트

insert into test_table value('id01', 'title-new') on duplicate key update title='title-new';

 

* SELECT 내용을 텍스트 파일로 저장하기

필드는 '\t'로 구분하고 라인은 '\n'로 구분한다.

생성된 파일은 find 로 찾는다.

MariaDB [test_db]> SELECT * INTO OUTFILE 'out.txt' FIELDS terminated by '\t' lines terminated by '\n' FROM snim_table;
Query OK, 1843 rows affected (0.02 sec)
MariaDB [test_db]> quit
Bye
root@ncpmicro:~# find / -name out.txt

 

MariaDB

1. 아래 MariaDB 홈페이지 방문

 

Download MariaDB Connectors for data access & analysis | MariaDB

Download MariaDB Connector/Python, MariaDB Connector/C, MariaDB Connector/J, MariaDB Connector/Node.js, MariaDB Connector/R2DBC, MariaDB Connector/ODBC and more

mariadb.com

 

2. Connectors 탭에서 Java8 옵션을 선택했고 아래에 파일 url 이 표시된다

3. Java8 Connector 파일을 wget 으로 다운 받아본다.

root@ncpmicro:/home# wget https://dlm.mariadb.com/1611425/Connectors/java/connector-java-3.0.0-alpha/mariadb-java-client-3.0.0-alpha.jar

 

4. 다운로드한 jar 파일을 java 설치디렉토리의 /lib/ext 디레토리에 복사한다.

root@ncpmicro:/home# cp mariadb-java-client-3.0.0-alpha.jar /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext

5. CLASSPATH 를 정의하기 위해 ~/.bashrc 수정

root@ncpmicro:/home# vi ~/.bashrc

6. 추가후 저장 - 각자 사정에 따라 다를 수 있음.

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH="$PATH:$JAVA_HOME/bin"
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext:.

7. 실행시킨다.

root@ncpmicro:/home# source ~/.bashrc

8. 이제 Java 소스를 컴파일 하여 MariaDB 를 테스트 할 수 있다.

그전에 테스트할 DB를 준비해야 하니 다음 편에 

요약
mysql
SHOW DATABASES;
USE database_name;
SHOW TABLES;
DESC table_name;

SHOW TABLE STATUS;
SELECT * FROM table_name;
exit

마리아DB 설치 명령 

apt install mariadb-server 입력해주면 아래와 같이 실행된다.

root@ncpmicro:~# apt install mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
...
...
...
0 upgraded, 29 newly installed, 0 to remove and 19 not upgraded.
Need to get 24.0 MB of archives.
After this operation, 184 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Y를 입력하면 한동안 설치 작업을 한다.

Get:1 http://kr.archive.ubuntu.com/ubuntu bionic/main amd64 mysql-common all 5.8+1.0.4 [7,308 B]
...
(중략)
...
Get:29 http://kr.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 mariadb-server all 1:10.1.48-0ubuntu0.18.04.1 [12.9 kB]
Fetched 24.0 MB in 7s (3,242 kB/s)
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 126286 files and directories currently installed.)
...
...
Unpacking mariadb-server (1:10.1.48-0ubuntu0.18.04.1) ...
Setting up libhtml-tagset-perl (3.20-3) ...
...
...
Setting up mariadb-server-10.1 (1:10.1.48-0ubuntu0.18.04.1) ...
Setting up mariadb-server (1:10.1.48-0ubuntu0.18.04.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
...
root@ncpmicro:~#

몇분 걸린듯 설치 끝 !!

 

시작하고 종료해 보기

mysql

exit

root@ncpmicro:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

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)]>
MariaDB [(none)]> exit
Bye
root@ncpmicro:~#

 

데이터베이스 명령어는 대문자 소문자를 가리지 않지만

가독성을 위해 대문자를 사용한다고 합니다.

 

데이터베이스 목록 보고 사용하기

SHOW DATABASES;

USE database;

root@ncpmicro:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

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 |
| mysql              |
| performance_schema |
+--------------------+
3 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]>

사용할 데이터베이스 테이블 조회 

SHOW TABLES;

MariaDB [mysql]> SHOW TABLES;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| gtid_slave_pos            |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| index_stats               |
| innodb_index_stats        |
| innodb_table_stats        |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| roles_mapping             |
| servers                   |
| slow_log                  |
| table_stats               |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
30 rows in set (0.00 sec)

MariaDB [mysql]>

테이블 속성 보기

DESC table_name;

MariaDB [mysql]> desc user;
+------------------------+-----------------------------------+------+-----+----------+-------+
| Field                  | Type                              | Null | Key | Default  | Extra |
+------------------------+-----------------------------------+------+-----+----------+-------+
| Host                   | char(60)                          | NO   | PRI |          |       |
| User                   | char(80)                          | NO   | PRI |          |       |
| Password               | char(41)                          | NO   |     |          |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Insert_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Update_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Delete_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Create_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Drop_priv              | enum('N','Y')                     | NO   |     | N        |       |
| Reload_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Shutdown_priv          | enum('N','Y')                     | NO   |     | N        |       |
| Process_priv           | enum('N','Y')                     | NO   |     | N        |       |
| File_priv              | enum('N','Y')                     | NO   |     | N        |       |
| Grant_priv             | enum('N','Y')                     | NO   |     | N        |       |
| References_priv        | enum('N','Y')                     | NO   |     | N        |       |
| Index_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Alter_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Show_db_priv           | enum('N','Y')                     | NO   |     | N        |       |
| Super_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N        |       |
| Lock_tables_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Execute_priv           | enum('N','Y')                     | NO   |     | N        |       |
| Repl_slave_priv        | enum('N','Y')                     | NO   |     | N        |       |
| Repl_client_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Create_view_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Show_view_priv         | enum('N','Y')                     | NO   |     | N        |       |
| Create_routine_priv    | enum('N','Y')                     | NO   |     | N        |       |
| Alter_routine_priv     | enum('N','Y')                     | NO   |     | N        |       |
| Create_user_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Event_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Trigger_priv           | enum('N','Y')                     | NO   |     | N        |       |
| Create_tablespace_priv | enum('N','Y')                     | NO   |     | N        |       |
| ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |          |       |
| ssl_cipher             | blob                              | NO   |     | NULL     |       |
| x509_issuer            | blob                              | NO   |     | NULL     |       |
| x509_subject           | blob                              | NO   |     | NULL     |       |
| max_questions          | int(11) unsigned                  | NO   |     | 0        |       |
| max_updates            | int(11) unsigned                  | NO   |     | 0        |       |
| max_connections        | int(11) unsigned                  | NO   |     | 0        |       |
| max_user_connections   | int(11)                           | NO   |     | 0        |       |
| plugin                 | char(64)                          | NO   |     |          |       |
| authentication_string  | text                              | NO   |     | NULL     |       |
| password_expired       | enum('N','Y')                     | NO   |     | N        |       |
| is_role                | enum('N','Y')                     | NO   |     | N        |       |
| default_role           | char(80)                          | NO   |     |          |       |
| max_statement_time     | decimal(12,6)                     | NO   |     | 0.000000 |       |
+------------------------+-----------------------------------+------+-----+----------+-------+
46 rows in set (0.00 sec)

MariaDB [mysql]>

테이블 상태 조회

SHOW TABLE STATUS;

MariaDB [mysql]> show table status;
+---------------------------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+---------------------------------------------------+
| Name                      | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length    | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time          | Collation         | Checksum | Create_options     | Comment                                           |
+---------------------------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+---------------------------------------------------+
| column_stats              | MyISAM |      10 | Dynamic    |    0 |              0 |           0 |    281474976710655 |         4096 |         0 |           NULL | 2021-08-26 15:26:50 | 2021-08-26 15:26:50 | NULL                | utf8_bin          |     NULL |                    | Statistics on Columns                             |
| columns_priv              | MyISAM |      10 | Fixed      |    0 |              0 |           0 | 282037926664077311 |         4096 |         0 |           NULL | 2021-08-26 15:27:19 | 2021-08-26 15:27:19 | 2021-08-26 15:27:19 | utf8_bin          |     NULL |                    | Column privileges                                 |
...
...
| user                      | MyISAM |      10 | Dynamic    |    1 |             72 |          72 |    281474976710655 |         4096 |         0 |           NULL | 2021-08-26 15:27:31 | 2021-08-26 15:27:31 | NULL                | utf8_bin          |     NULL |                    | Users and global privileges                       |
+---------------------------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+---------------------------------------------------+

 

테이블 데이터 조회하기

SELECT * FROM table;

MariaDB [mysql]> select * from help_category;
+------------------+-----------------------------------------------+--------------------+-----+
| help_category_id | name                                          | parent_category_id | url |
+------------------+-----------------------------------------------+--------------------+-----+
|                1 | Geographic                                    |                  0 |     |
|                2 | Polygon properties                            |                 34 |     |
|                3 | WKT                                           |                 34 |     |
|                4 | Numeric Functions                             |                 38 |     |
|                5 | Plugins                                       |                 35 |     |
|                6 | MBR                                           |                 34 |     |
|                7 | Control flow functions                        |                 38 |     |
|                8 | Transactions                                  |                 35 |     |
|                9 | Help Metadata                                 |                 35 |     |
|               10 | Account Management                            |                 35 |     |
|               11 | Point properties                              |                 34 |     |
|               12 | Encryption Functions                          |                 38 |     |
|               13 | LineString properties                         |                 34 |     |
|               14 | Miscellaneous Functions                       |                 38 |     |
|               15 | Logical operators                             |                 38 |     |
|               16 | Functions and Modifiers for Use with GROUP BY |                 35 |     |
|               17 | Information Functions                         |                 38 |     |
|               18 | Comparison operators                          |                 38 |     |
|               19 | Bit Functions                                 |                 38 |     |
|               20 | Table Maintenance                             |                 35 |     |
|               21 | User-Defined Functions                        |                 35 |     |
|               22 | Data Types                                    |                 35 |     |
|               23 | Compound Statements                           |                 35 |     |
|               24 | Geometry constructors                         |                 34 |     |
|               25 | GeometryCollection properties                 |                  1 |     |
|               26 | Administration                                |                 35 |     |
|               27 | Data Manipulation                             |                 35 |     |
|               28 | Utility                                       |                 35 |     |
|               29 | Language Structure                            |                 35 |     |
|               30 | Geometry relations                            |                 34 |     |
|               31 | Date and Time Functions                       |                 38 |     |
|               32 | WKB                                           |                 34 |     |
|               33 | Procedures                                    |                 35 |     |
|               34 | Geographic Features                           |                 35 |     |
|               35 | Contents                                      |                  0 |     |
|               36 | Geometry properties                           |                 34 |     |
|               37 | String Functions                              |                 38 |     |
|               38 | Functions                                     |                 35 |     |
|               39 | Data Definition                               |                 35 |     |
+------------------+-----------------------------------------------+--------------------+-----+
39 rows in set (0.00 sec)

MariaDB [mysql]>
요약
mysql
SHOW DATABASES;
USE database_name;
SHOW TABLES;
SHOW TABLE STATUS;
SELECT * FROM table_name;
exit

+ Recent posts