DB/전체

MAC mariaDB 설치 및 실행 : 오류 발생 시 대응, 클라이언트, 서버 실행

have a nice day :D 2025. 3. 12. 16:04
반응형
MAC mariaDB 설치 및 실행
기본 설치 및 실행 포함
오류 발생 시, 완전 히 삭제 후 재설치 포함
DB 클라이언트 확인 포함
SpringBoot 연동 확인 포함

 

Homebrew로 MariaDB 설치

1. 설치

Homebrew 설치
Homebrew : Mac에서 터미널을 이용해 소프트웨어를 쉽게 설치하고 관리할 수 있도록 도와주는 패키지 관리자. (설치/실행/삭제)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Homebrew로 MariaDB 설치

brew install mariadb

설치 확인

mysql --version

 

2. 실행

MariaDB 서버 시작

brew services start mariadb

MariaDB 서버 정지

brew services stop mariadb

MariaDB 서버 재시작

brew services restart mariadb
 3. 접속 및 설정
mysql -u root

오류 발생 시,
% mysql -u root ERROR 1698 (28000): Access denied for user 'root'@'localhost'

sudo mysql -u root

root 계정 비밀번호 설정 : 처음 실행

ALTER USER 'root'@'localhost' IDENTIFIED BY '새로운비밀번호';
FLUSH PRIVILEGES;

MariaDB 기본 설정 변경(옵션)
MariaDB 설정 파일 : /usr/local/etc/my.cnf

brew services restart mariadb

 3-1. 비빌번호 설정 후 접속
% mysql -u root -p (엔터)

my@MYui-iMac ~ % mysql -u root -p  
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 11.7.2-MariaDB Homebrew

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. 설치 제거 (삭제)
brew uninstall mariadb

설정 및 데이터 모두 삭제

rm -rf /usr/local/var/mysql
rm -rf /usr/local/etc/my.cnf

4-1. 설치 오류로 삭제 후 재설치
- 설치 오류 발생 1.
my@MYui-iMac ~ % sudo mysqld_safe --skip-grant-tables & [2] 87072 my@MYui-iMac ~ % /usr/local/bin/mysqld_safe: Deprecated program name. It will be removed in a future release, use 'mariadbd-safe' instead 250313 09:39:43 mysqld_safe Logging to '/usr/local/var/MYui-iMac.local.err'. 250313 09:39:43 mysqld_safe Starting mariadbd daemon with databases from /usr/local/var /usr/local/bin/mariadbd-safe-helper: Can't create/write to file '/usr/local/var/MYui-iMac.local.err' (Errcode: 13 "Permission denied") [2] - exit 1 sudo mysqld_safe --skip-grant-tables

- 설치 오류 발생 2.
MariaDB [(none)]> alter user 'root'@'localhost' identified by ‘[새로운비밀번호]'; ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

- 설치 오류 발생 3.
MariaDB [(none)]> flush privileges; ERROR 1146 (42S02): Table 'mysql.db' doesn't exist

5. 완전히 삭제 후 재설치 처리

실행 중인 MariaDB 강제 종료

sudo killall mariadbd
#또는
sudo killall mysqld

실행 중인 프로세스 확인

ps aux | grep mariadb

정상,
my@MYui-iMac ~ % ps aux | grep mariadb my 1251 0.0 0.0 34121336 712 s000 S+ 10:36AM 0:00.00 grep mariadb
현재 grep으로 요청한 정보만 표현되면 '정상'

기존 MariaDB 설정 및 데이터 완전 삭제

#순차 실행
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/etc/my.cnf
sudo rm -rf /usr/local/Cellar/mariadb
sudo rm -rf /Users/my/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

Homebrew 업데이트 및 리셋

#순차 실행
brew update
brew upgrade
brew doctor

다시 위에서 부터 순차 실행

brew install mariadb
6. 정상 수행

MAC에서 가장 많이 사용하는 데이터베이스 클라이언트 (무료)
https://dbeaver.io/download/

 

Download | DBeaver Community

Download DBeaver Community 25.0.0 Released on March 2nd 2025 (Milestones). It is free and open source (license). Also you can get it from the GitHub mirror. System requirements. DBeaver PRO 24.3 Released on December 16th, 2024 PRO version website: dbeaver.

dbeaver.io

설치 후,
1) mariadb 선택
2) 사용자 명 : root
3) 비밀번호 : 설정한 비밀번호
4) 확인 버튼 클릭 하면, 드라이브 설치 메세지 나오면 확인 클릭 -> 설치 후 아래와 같이 정상접속

7. SpringBoot application.yml 설정
spring:
  datasource:
    url: jdbc:mariadb://localhost:3306/test  # 데이터베이스 URL, 기본 port, 기본 DB
    username: root  # MariaDB 계정
    password: 비밀번호  # MariaDB 비밀번호
    driver-class-name: org.mariadb.jdbc.Driver  # MariaDB 드라이버 지정

  jpa:
    database-platform: org.hibernate.dialect.MariaDBDialect  # Hibernate에서 사용할 MariaDB Dialect
    hibernate:
      ddl-auto: update  # 스키마 자동 생성 전략 (update / create / none)
    show-sql: true  # SQL 쿼리 콘솔에 출력
    properties:
      hibernate:
        format_sql: true  # SQL을 보기 좋게 출력

  sql:
    init:
      mode: always  # 애플리케이션 시작 시 SQL 스크립트 실행

7-1. Java Entity 설정과 서버 기동 시 자동 생성 (with hibernate)

package com.example.demojpa2.entity;

import jakarta.persistence.*;

@Entity
public class Notice {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Column(nullable = false, length = 100)
    private String title;

    @Column(nullable = true, length = 1000)
    private String content;
}
더보기

서버 정상 기동

 Tomcat initialized with port 8080 (http)
 Starting service [Tomcat]
 Starting Servlet engine: [Apache Tomcat/10.1.36]
 Initializing Spring embedded WebApplicationContext
 Root WebApplicationContext: initialization completed in 1131 ms
 HHH000204: Processing PersistenceUnitInfo [name: default]
 HHH000412: Hibernate ORM core version 6.6.8.Final
 HHH000026: Second-level cache disabled
 No LoadTimeWeaver setup: ignoring JPA class transformer
 HikariPool-1 - Starting...
 HikariPool-1 - Added connection org.mariadb.jdbc.Connection@769eb0b9
 HikariPool-1 - Start completed.
 HHH90000025: MariaDBDialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
 HHH10001005: Database info:
    Database JDBC URL [Connecting through datasource 'HikariDataSource (HikariPool-1)']
    Database driver: undefined/unknown
    Database version: 11.7.2
    Autocommit mode: undefined/unknown
    Isolation level: undefined/unknown
    Minimum pool size: undefined/unknown
    Maximum pool size: undefined/unknown
[  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: 
    create table notice (
        id bigint not null,
        content varchar(1000),
        title varchar(100) not null,
        primary key (id)
    ) engine=InnoDB
Hibernate: 
    create sequence notice_seq start with 1 increment by 50 nocache
Initialized JPA EntityManagerFactory for persistence unit 'default'
spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
H2 console available at '/h2-console'. Database available at 'jdbc:mariadb://localhost/test?user=root&password=***'
LiveReload server is running on port 35729
Tomcat started on port 8080 (http) with context path '/'
Started Demojpa2Application in 3.732 seconds (process running for 4.422)

 

반응형