본문 바로가기

인프라/Docker

Docker ubuntu에 MySql 사용하기

가장 간단한 방법은

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=[패스워드] mysql

사용 하는 방법인데

 

이번에는 우분투 환경에 mysql를 설치해볼 예정입니다.

우분투 실행

docker container run -d  --privileged=true ubuntu sleep infinity

명령어를 통해 systemctl 과 mysql를 설치 해 줍니다.

apt install -y systemd mysql-server

명령어를 통해 mysql 실행

service mysql start

mysql 접속 및 사용자 추

root@d16ad900a5a2:/# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.35-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2023, 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> create user 'user'@'%'identified by '[비밀번호]';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* TO 'user'@'%';
Query OK, 0 rows affected (0.00 sec)

완료