MySQL

install

EC2 AMI2023

wget https://dev.mysql.com/get/mysql80-community-release-el9-5.noarch.rpm
sudo dnf install mysql80-community-release-el9-5.noarch.rpm
sudo dnf update
sudo dnf install mysql-community-server
sudo systemctl start mysqld
sudo grep 'temporary password' /var/log/mysqld.log
mysql> create user 'devuser'@'localhost' identified by 'devpass';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> create user 'devuser'@'localhost' identified by 'Devpass';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> create user 'devuser'@'localhost' identified by 'Devpass!';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> create user 'devuser'@'localhost' identified by 'Devpass!2';
Query OK, 0 rows affected (0.01 sec)

Mac

# mysql μ„€μΉ˜
# (이전에 μ„€μΉ˜ λ˜μ–΄ μžˆλ‹€λ©΄ μ•„λž˜ μ‚­μ œ μ°Έκ³ )
brew install mysql
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/8.0.23: 298 files, 297.8MB
➜  var mysql.server start
Starting MySQL
# μ„œλ²„ μ‹œμž‘
mysql.server start

# λ³΄μ•ˆ μ„€μ •
mysql_secure_installation

# ν„°λ―Έλ„μ—μ„œ 접속
mysql -u root -p
Enter password:

DB, 계정 생성

mysql -u root -p
Enter password:

show databases;
create database devdb default character set utf8mb4 collate utf8mb4_unicode_ci;
drop database devdb;

# DB(devdb) 생성
create database devdb default character set utf8mb4 collate utf8mb4_unicode_ci;
show databases;

# devuser 계정 생성, λΉ„λ²ˆμ€ Devpass!2
create user 'devuser'@'localhost' identified by 'Devpass!2';

# devdb의 λͺ¨λ“  κΆŒν•œμ„ devuser κ³„μ •μ—κ²Œ λΆ€μ—¬
# `localhost`μ—μ„œλ§Œ 접속 κ°€λŠ₯. μ™ΈλΆ€λŠ” `%`
grant all on devdb.* to 'devuser'@'localhost';

use devdb;
show tables;

# λ˜λŠ” ctrl+D
exit;

μ‚­μ œ

# mysql μ’…λ£Œ
mysql.server stop

# mysql μ„œλ²„ μ‚­μ œ
brew uninstall mysql
Uninstalling /usr/local/Cellar/mysql/8.0.23... (298 files, 297.8MB)

# 데이터 폴더 확인
ls /usr/local/var/mysql
#ib_16384_0.dblwr            binlog.index                 ib_logfile1                  server-cert.pem
#ib_16384_1.dblwr            ca-key.pem                   ibdata1                      server-key.pem
#innodb_temp                 ca.pem                       ibtmp1                       sys
KENUui-MacBook-Pro.local.err client-cert.pem              mysql                        undo_001
KENUui-MacBook-Pro.local.pid client-key.pem               mysql.ibd                    undo_002
auto.cnf                     devdb                        performance_schema
...

# 데이터 폴더 μ‚­μ œ
rm -rf /usr/local/var/mysql
# devuser 계정 접속 ν…ŒμŠ€νŠΈ
mysql -u devuser -p devdb
bye

JDBC info

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/devdb?useUnicode=true&charaterEncoding=utf-8&allowPublicKeyRetrieval=true&useSSL=false
# 8.0 λΆ€ν„° 둜컬 κ°œλ°œμ‹œ `allowPublicKeyRetrieval`, `useSSL` μ„€μ • ν•„μš”
spring.datasource.username=devuser
spring.datasource.password=Devpass!2

Data path

Functions

select str_to_date('2021-04-14T04:42:00.000Z','%Y-%m-%dT%T.%fZ');
-- timezone
select CONVERT_TZ(str_to_date('2021-04-06T04:42:00.000Z','%Y-%m-%dT%T.%fZ'), '+09:00', 'system');

related

What Else?
inflearn react api server -50% 할인쿠폰: 20652-ab1f1cd4c373 buy me a coffee