[MariaDB]0. 무작정 시작하기

HW·2023년 3월 1일
0

MariaDB

목록 보기
1/4
post-thumbnail

설치환경

  • Ubuntu 20.04
  • mariaDB 10.3.37

설치

sudo apt update
sudo apt-get -y upgrade
sudo apt-get install -y mariadb-server

재부팅 시 자동실행 설정

sudo systemctl enable mariadb

MariaDB 설정

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.

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.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
루트 암호를 변경하시겠습니까? [Y/n] n

... skipping.

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.

기본적으로, MariaDB에는 익명 사용자가 있으며, 테스트를 위해
모든 사용자가 익명 사용자로 접속할 수 있습니다.
본격 서비스가 실시되기 전에 이 익명 사용자는 삭제 되어야 합니다.

Remove anonymous users? [Y/n] Y
익명 사용자를 제거하시겠습니까? [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는 lcoalhost에서만 접속이 되어야 합니다.
누군가 root의 비밀번호를 추측할 수 없도록 하기 위함이죠.

Disallow root login remotely? [Y/n] Y
원격 접속을 불허하시겠습니까?? [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.

기본적으로, MariaDB에는 test라는 database가 생성되어 있습니다.
이것 또한 테스트를 위함이며, 본격 서비스가 실시되기 전에
삭제되어야 합니다.

Remove test database and access to it? [Y/n] Y
test database를 제거하시겠습니까? [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.

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.

MariaDB 서비스 확인

sudo systemctl status mariadb

MariaDB 접속

sudo mysql -u root -p

MariaDB 기본 명령어

#mysql DB 접속
use mysql;

# DB 만들기
CREATE DATABASE 데이터베이스명;

# DB 확인하기
SHOW DATABASES;

# DB 삭제하기
DROP DATABASE 데이터베이스명;

#사용자 생성
## 로컬접속용
CREATE USER '사용자명'@'localhost' IDENTIFIED BY '비밀번호';
## 외부접속용
CREATE USER '사용자명'@'%' IDENTIFIED BY '비밀번호';
 
# 사용자 확인
SELECT User, Host, Password FROM mysql.user;

#사용자 삭제
## 로컬접속용
DROP USER '사용자명'@'localhost';
## 외부접속용
DROP USER '사용자명'@'%';

# 권한 부여
## 로컬접속용
GRANT ALL PRIVILEGES ON 데이터베이스명.* TO '사용자명'@'localhost';
## 외부접속용
GRANT ALL PRIVILEGES ON 데이터베이스명.* TO '사용자명'@'%';

# 권한 제거
REVOKE ALL PRIVILEGES ON 데이터베이스명.* FROM '사용자명'@'%';

# 갱신
FLUSH PRIVILEGES;
profile
예술융합형 개발자🎥

0개의 댓글