MySQL
install
EC2 AMI2023
- MySQL 8.0 Community Server
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
sudo mysql_secure_installation -p
mysql -u root -p
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)
create user 'devuser'@'localhost' identified by 'Devpass!2';
grant all privileges on devdb.* to 'devuser'@'localhost';
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
/usr/local/var/mysql
- uninstallν λ μμ νμν μλ μμ.
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