우분투를 사용하는 경우 apt-get 명령을 사용하여 데이터베이스 패키지를 제거합니다.

함께 설치된 mariadb 패키지를 확인한 후 관련 패키지 모두를 삭제합니다.

$ sudo dpkg -l | grep mariadb 

ii  mariadb-client-10.3                        1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database client binaries
ii  mariadb-client-core-10.3                   1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database core client binaries
ii  mariadb-common                             1:10.3.32-0ubuntu0.20.04.1            all          MariaDB common metapackage
ii  mariadb-server                             1:10.3.32-0ubuntu0.20.04.1            all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.3                        1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database server binaries
ii  mariadb-server-core-10.3                   1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database core server files

 

다음 명령어로 mariadb 서버 및 관련 패키지를 삭제합니다.

 $ sudo apt-get purge mariadb-server
 $ sudo apt-get purge mariadb-server-10.3
 $ sudo apt-get purge mariadb-client-10.3
 $ sudo apt-get purge mariadb-server-core-10.3
 $ sudo apt-get purge mariadb-client-core-10.3
 $ sudo apt-get purge mariadb-common

 

 

서버 버전 확인

실행 중인 MySQL 또는 MariaDB 서버 버전에 따라 다른 명령어로 루트 암호를 복구해야 합니다.

다음 명령을 실행하여 서버 버전을 확인합니다.

mysql --version

시스템에 MySQL이 설치되어 있는 경우 출력은 다음과 같습니다.

mysql  Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using  EditLine wrapper

또는 MariaDB에 대해 다음과 같이 출력합니다.

mysql  Ver 15.1 Distrib 10.3.32-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

 

MySQL 또는 MariaDB 루트 비밀번호를 재설정하는 방법

MySQL/MariaDB 루트 비밀번호를 재설정하려면 다음 단계를 수행합니다.

 

1. MySQL/MariaDB 서비스 중지

만일 mysql이나 mariaDB가 기동 중에 있을 경우, 루트 암호를 변경하려면 먼저 MySQL 서버를 중지해야 합니다. 

 

sudo systemctl stop mysql

 

2. 그랜트 테이블을 로드하지 않고 MySQL/MariaDB 서버를 시작합니다.

그랜트 테이블을 로드하지 않고 데이터베이스 서버를 시작합니다:

sudo mysqld_safe --skip-grant-tables &

위의 명령 끝에 있는 &(앰퍼샌드)는 프로그램이 백그라운드에서 실행 되도록 하므로 쉘을 계속 사용할 수 있습니다.

--skip-grant-tables옵션을 사용하면 누구나 암호 없이 데이터베이스 서버에 연결할 수 있습니다.

 

3. MySQL 셸에 로그인

이제 루트 사용자로 데이터베이스 서버에 연결할 수 있습니다.

mysql -u root

 

4. 새 루트 비밀번호 설정

MySQL 5.7.5 및 이전 버전 또는 MariaDB 10.1.20 및 이전 버전인 경우

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MY_NEW_PASSWORD');
FLUSH PRIVILEGES;

 

MySQL 5.7.6 이상 또는 MariaDB 10.1.20 이상인 경우

MariaDB> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
MariaDB> FLUSH PRIVILEGES;

 

ALTER USER문이 수행되지 않고 아래와 같이 오류가 발생하면 UPDATE 문을 수행합니다.

MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

 

오류 발생 시 아래 SQL문을 수행합니다.

MariaDB> UPDATE mysql.user SET authentication_string = PASSWORD('NEW_PASSWORD')
WHERE User = 'root' AND Host = 'localhost';

MariaDB> FLUSH PRIVILEGES;

 

5. 데이터베이스 서버를 정상적으로 중지 및 시작

이제 루트 암호가 설정되었으므로 데이터베이스 서버를 중지하고 정상적으로 시작합니다.

$ mysqladmin -u root -p shutdown

새 루트 암호를 입력하라는 메시지가 표시됩니다. 암호를 입력하면 데이터베이스 서버를 정상적으로 중지합니다.

 

데이터베이스 기동

MySQL의 경우 다음을 입력합니다.

sudo systemctl start mysql

MariaDB의 경우 다음을 입력합니다.

sudo systemctl start mariadb

 

***  참고 ***

WSL 에서  sudo systemctl start mysql, sudo systemctl start mariadb 명령어로 DB 기동 시 아래 오류가 발생하면

 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

 

아래 명령어로 DB를 기동한다.

sudo /etc/init.d/mysql start

 

 

6. 비밀번호 확인

새 루트 암호가 올바르게 적용되었는지 확인하려면 다음을 입력합니다.

sudo mysql -u root -p

새 루트 암호를 입력하라는 메시지가 표시됩니다. 입력하면 데이터베이스 서버에 로그인 합니다.

 

Unable to correct problems, you have held broken packages MYSQL 오류 메시지

당황스럽군. 

 

$ sudo apt-get install mysql-server

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-server : Depends: mysql-server-8.0 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

 

해결책

aptitude 를 설치한 후에 다시 mysql-server를 설치합니다.

- sudo apt-get install aptitude

- sudo aptitude install mysql-server

$ sudo apt-get install aptitude

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  aptitude-common libboost-iostreams1.71.0 libclass-accessor-perl libcwidget4 libio-string-perl
  libparse-debianchangelog-perl libsigc++-2.0-0v5 libsub-name-perl libxapian30
Suggested packages:
  aptitude-doc-en | aptitude-doc apt-xapian-index debtags tasksel libcwidget-dev libxml-simple-perl xapian-tools
The following NEW packages will be installed:
  aptitude aptitude-common libboost-iostreams1.71.0 libclass-accessor-perl libcwidget4 libio-string-perl
  libparse-debianchangelog-perl libsigc++-2.0-0v5 libsub-name-perl libxapian30
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 4343 kB of archives.

$ sudo apt-get install mysql-server

 

 

 

'MariaDB' 카테고리의 다른 글

Ubuntu 20.04에 MariaDB 삭제하기  (0) 2022.01.15
mariadb, mysqlDB root password 초기화  (0) 2022.01.14
Ubuntu 20.04에 MariaDB 설치하기  (0) 2021.12.28
MariaDB 삭제-수정  (0) 2021.12.28
MariaDB Products  (0) 2021.12.28

윈도우10 WSL 에 설치된 Ubuntu 20.04 에 MariaDB 설치하기

[ 설치환경 ]

  • Microsoft Windows 10 Pro(10.0.19041 N/A 빌드 19041)
  • WSL 2(Ubuntu 20.04 LTS)

 

설치순서

  1. wsl에 접속
  2. mariadb-server 목록 조회 : 설치할 mariadb-server 목록조회
  3. mariadb-server 설치:  DBMS 서버 설치 (필수)
  4. mysql_secure_installation: 보안 설정
  5. mariadb 접속 및 SQL 수행 

WSL 에 접속

윈도우 command 창이나 Window PowerShell 창에서 wsl 명령어를 수행하여 wsl에 접속한다. wsl에 접속한다는 것은 wsl 이 기동하는 Ubuntu Linux에 접속하는 것이다. 문서에서 "$" 표시는 wsl 접속된 상태를 의미한다.

PS D:\> wsl
username@computername:/mnt/d$

 

mariadb-server 설치:  DBMS 서버 설치 

아래 명령어로 mariaDB server(DBMS)를 설치한다. 위에서 확인한 mariadb-server-10.3 버전을 설치한다.

mariadb-client-10.3, mariadb-client-core-10.3, mariadb-common mariadb-server-core-10.3, socat 도 같이 설치되므로 별도로 client를 설치할 필요는 없다.

mariadb-server 설치후 sudo apt-get install mariadb-client-10.3 명령어를 수행하면 이미 설치되었다는 메시지가 출력된다.

$ sudo apt-get 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:
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  galera-3 libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl
  mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server-core-10.3 socat
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl mailx mariadb-test tinyca
The following NEW packages will be installed:
  galera-3 libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl
  mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server-10.3 mariadb-server-core-10.3 socat
0 upgraded, 13 newly installed, 5 to remove and 0 not upgraded.
Need to get 20.6 MB of archives.
After this operation, 32.6 MB disk space will be freed.
Do you want to continue? [Y/n]

위의 명령어에 sudo 명령어를 붙인 이유는 root 권한으로 설치해야 한다. 그렇지 않으면 아래 오류가 발생한다.

$ apt-get install mariadb-server
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

 

설치가 완료된 후 MariaDB 서비스가 자동으로 시작되지 않으므로 다음 명령을 사용하여 MariaDB 서비스를 시작합니다.

$ sudo service mysql start
 * Starting MariaDB database server mysqld

 

mysql_secure_installation: 보안 설정

mysql_secure_installation 명령어로 root 패스워드 설정, anonymous user 삭제 여부,  root 원격접속허용 여부, 테스트 데이터베이스 삭제 여부, 테이블 권한 갱신 여부 등을 선택하는 작업을 수행한다.

$ sudo 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.
Set root password? [Y/n] Y
New password:
Enter current password for root (enter for none):

... ...
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

최초 설치 시 루트 암호 빈값이므로 " Enter "를 누릅니다.

root에 대한 새로운 암호설정 여부에서 'Y'를 입력 후 암호를 설정합니다. 

 

 

 

mariadb 접속 및 SQL 수행

MariaDB가 정상 동작하는지 확인하기 위해서 wsl 터미널에서 mariadb를 실행하고 MariaDB console에서 명령어를 입력합니다.  MariaDB에서 SQL 명령어 끝에 세미콜론(;)을 입력하고 엔터를 치면 실행 결과를 출력합니다.

 

wsl 콘솔에서 아래 명령어를 수행하면 wsl 계정의 패승워드를 입력하라는 메시지가 뜨는데, wsl 생성 시 입력한 패스워드를 입력합니다. 패스워드를 입력하면 바로 mariadb에 접속됩니다. 패스워드를 묻지 않고 바로 접속될 수도 있습니다.

$ sudo mariadb
[sudo] password for username :

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 66
Server version: 10.3.32-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.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.

 

Maria DB 에서 SQL 명령어를 실행한다. 

현재 생성되어 있는 database 목록을 출력한다 

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

 

설치된 Maria DB 버전을 확인한다.  10.3 version이  설치된 것을 확인 할 수 있다.

MariaDB [(none)]> select version();
+----------------------------------+
| version()                        |
+----------------------------------+
| 10.3.32-MariaDB-0ubuntu0.20.04.1 |
+----------------------------------+
1 row in set (0.000 sec)

 

계정 정보에 대해 조회해 봅니다. 위에서 계정과 패스워드없이 DB에 접속한 한 것은 root 인증 방식이 unix_socket 방식으로 설정되어 있어 패스워드 없이 접속된 것입니다.

MariaDB [mysql]> select host,user,plugin from user;
+-----------+------+-------------+
| host      | user | plugin      |
+-----------+------+-------------+
| localhost | root | unix_socket |
+-----------+------+-------------+
1 row in set (0.000 sec)

WSL 쉘에서 다음 접속 명령어를 수행하면 접속 오류가 발생합니다. 이는 인증 방식이 unix_sokcet 방식으로 지정되어 있기 때문입니다.

$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

 

 

root로 mysql password 방식으로 변경하려면 다음을 수행합니다.

sudo mysql

MariaDB> update mysql.user set plugin = 'mysql_native_password' where User='root';
MariaDB> FLUSH PRIVILEGES;

MariaDB [(none)]> select host,user,plugin from mysql.user;
+-----------+------+-----------------------+
| host      | user | plugin                |
+-----------+------+-----------------------+
| localhost | root | mysql_native_password |
+-----------+------+-----------------------+
1 row in set (0.000 sec)

MariaDB> exit;

인증 방식이 기존 unix_sokcet 방식에서 mysql_native_password 방식으로 변경된 것을 확인할 수 있습니다.

이제 쉘에서 아래처럼 db 접속 명령어를 수행하면 DB 접속이 잘 됩니다.

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 59
Server version: 10.3.32-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.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 관리툴로 접속

mysql, mariaDB 관리 툴로는 HeidiSQL, DBever, Toad for mysql, SQL Developer, MySQL Workbench 등 다양하게 존재합니다. 이중 HeidiSQL 로 mariaDB 접속을 설명합니다.

 

HeidiSQL 접속

WSL에서도 MySQL 8.0에 연결하도록 HeidiSQL을 구성할 수 있습니다.

https://www.heidisql.com/download.php 에서 HeidiSQL 을 다운로드 후 설치합니다.

설치 완료 후 heidisql 을 실행합니다.

 

  • 새로 만들기를 클릭하고 연결에 mariaDB-WSL2을 입력합니다. 이름은 임의로 각자 정할수 있습니다.
  • Library :  libmysql.dll, mariadb인 경우에는(libmariadb.dll 을 선택), 둘 다 접속은 가능
  • Hostname / IP: localhost
  • User: root
  • Password: root 패스워드 입력

 

만일, 아래와 같은 오류 메시지가 나면

'Access denied for user 'root'@'localhost' (using password: YES)'

mysql 또는 mariadb 접속 후 아래 명령어를 수행해 줍니다.

sudo mysql

MariaDB> update mysql.user set plugin = 'mysql_native_password' where User='root';
MariaDB> FLUSH PRIVILEGES;
MariaDB> exit;

 

MariaDB 중지

아래 명령어로 mariaDB를 중지합니다.

$ sudo service mysql stop
 * Stopping MariaDB database server mysqld

 

MariaDB를 완전히 제거하기 위해 MariaDB Knowledge Base와 Ubuntu community 설명이 약간 상이합니다.

MariaDB Knowledge Base 설명

MairaDB Knowledge Base에는 "우분투를 사용하는 경우" apt-get 명령을 사용하여 데이터베이스 패키지를 제거하라고 설명이 되어 있습니다.

https://mariadb.com/kb/en/uninstall-or-delete-mariadb-completely-for-re-installation/

$ sudo apt-get purge mariadb-server

You may check which mariadb packages are installed with:

$ sudo dpkg -l | grep mariadb

 

Ubuntu community 설명

이 페이지에서는 apt-get 및 관련 명령을 사용하여 시스템에서 패키지를 제거하는 방법을 설명합니다.

https://help.ubuntu.com/community/AptGet/Howto

 

아래 명령은 설치된 패키지를 제거하고 구성 파일은 그대로 둡니다.

 

apt-get remove <package_name>


아래 명령은 패키지 및 관련 구성 파일을 완전히 제거합니다. ~(home directory를 나타냄) 에 있는 구성 파일은 일반적으로 이 명령의 영향을 받지 않습니다

 

apt-get purge <package_name>

 

아래 명령은 다른 패키지에 의해 설치되어 더 이상 필요하지 않은 패키지를 제거합니다. 

 

apt-get autoremove


이 명령은 설치된 패키지와 종속성을 제거합니다.

apt-get autoremove <package_name>

 

  • While there is no built in way to remove all of your configuration information from your removed packages you can remove all configuration data from every removed package with the following command.

  • 제거된 패키지에서 모든 구성 정보를 제거하는 내장된 방법은 없지만 다음 명령을 사용하여 제거된 모든 패키지에서 모든 구성 데이터를 제거할 수 있습니다.
  • dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge

Search commands

 

 

mariadb의 설정 파일을 삭제하기 위해서 purge를 통해 삭제를 해줍니다.

$ sudo apt purge mariadb-*

apt purge명령어는 패키지를 제거하면 구성 파일과 함께 패키지를 삭제합니다. apt remove 명령은 패키지만 제거하지만 구성 파일은 그대로 유지됩니다. 

명령어를 실행하면 최신버전이나 다른 버전을 설치하기 위해서라면 데이터를 보관하라는 메지시지가 나타납니다. 데이터가 존재하고 보관해야 한다면, 별도 백업을 받고 삭제합니다. 화살표 키를 움직여 <Yes>선택하고 엔터키를 칩니다.

그 후 autoremove 명령어를 통해 패키지의 의존성 때문에 설치된 패키지들을 제거해 줍니다. mariadb와 관련되어 설치된 패키지들이 제거됩니다.

 

$ sudo apt autoremove

The following packages will be REMOVED:
  galera-3 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl
  libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl
  libio-html-perl liblwp-mediatypes-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl libtimedate-perl
  liburi-perl mysql-common socat
0 upgraded, 0 newly installed, 22 to remove and 0 not upgraded.
After this operation, 16.2 MB disk space will be freed.

 

mysql 관련 config 파일이 남아 있으니, dpkg 명령어를 사용하여 제거해 줍니다.

dpkg -l | grep mysql

rc  mysql-common                   5.8+1.0.5ubuntu2                      all          MySQL database common files, e.g. /etc/mysql/my.cnf

 

dpkg 예시화면

위처럼 mysql-common 이 보이면

sudo apt purge mysql-common

명령어를 통해 제거해줍니다.

 

그 후 꼭 REBOOT을 해줍니다.

sudo reboot

 

MariaDB 재설치
sudo apt install mariadb-server --fix-missing --fix-broken

<!--  --fix-missing --fix-broken를 사용하여 fetch to fail 에러를 대비합니다. -->

 

성공

오류 없이 정상적으로 잘 설치된 부분을 확인할 수 있습니다.

MaridDB 제품군은 3개이며

MariaDB Community Server(오픈 소스 관계형 데이터베이스),

MariaDB Enterprise(MariaDB Enerprise, MaxScale, ColumnStore, XPand로 구성),

MariaDB SkySQL(클라우드 서비스 Database) 입니다.

 

각각의 제품 특징입니다.

MariaDB Community Server

MariaDB Community Server는 전 세계 개발자들에게 사랑받는 오픈 소스 관계형 데이터베이스입니다. MySQL, Oracle 및 기타 SQL 데이터베이스와 호환되며 영원히 오픈 소스로 유지됩니다. 주요 기능에는 최신 SQL, 플러그형 스토리지 엔진, 분석 및 고가용성을 위한 컬럼 스토리지가 포함됩니다

  • Modern relational database
  • Compatible with MySQL
  • Massive ecosystem of tools and libraries
  • Open source/Community-supported

MariaDB Enterprise

MariaDB Enterprise는 트랜잭션, 분석 또는 하이브리드 트랜잭션/분석 워크로드는 물론 관계형 또는 문서 데이터를 처리할 수 있는 다용성과 독립 실행형 데이터베이스 및 열 형식 데이터 웨어하우스에서 초당 수백만 건의 트랜잭션을 실행하고 수십억 개의 행에 대해 대화형 임시 분석을 수행하는 분산 SQL 데이터베이스.

  • MariaDB Enterprise Server – Hardened version of MariaDB Community Server
  • MaxScale database proxy
  • ColumnStore MPP analytics
  • MariaDB Xpand distributed SQL engine
  • Backports, patches and CVEs
  • Consultative support

MariaDB SkySQL

SkySQL은 트랜잭션, 분석 및 하이브리드 워크로드에 대한 지원을 포함하여 MariaDB Enterprise의 모든 기능을 클라우드에 제공하는 서비스형 데이터베이스(DBaaS)입니다. Kubernetes를 기반으로 구축되고 클라우드 인프라 및 서비스에 최적화된 SkySQL은 사용 용이성과 셀프 서비스를 엔터프라이즈 안정성 및 지원을 제공합니다.

  • DataBase-As-A-Service (DBaaS) for systems of record
  • Multi-cloud – Deploy on AWS and GCP
  • Scale on demand – Scale out and back with your workload
  • Support from the source – 24x7x365 help when you need it
  • SkyDBAs – Database administrators to complement your team

+ Recent posts