![見出し画像](https://assets.st-note.com/production/uploads/images/138218444/rectangle_large_type_2_33baa871a9edf7e3b5496b6a892ea50d.jpeg?width=800)
djangoのデータベースをpostgresqlからmysqlに変更する
mysqlのインストール
brew install mysql
mysqlの起動
brew services start mysql
mysqlのシェルにログイン
mysql -u root -pパスワード(pとの間にスペースなし)
パスワード設定
sudo mysql_secure_installation
パスワードの長さや文字制限を設定
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password.length=4;
djangoでmysqlを使うときに"Authentication plugin 'caching_sha2_password' cannot be loaded..."と出たとき
select user, plugin from user;
alter user 'root'@'localhost' identified WITH mysql_native_password by 'パスワード';
settings.pyの変更
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': "作ったDB",
'USER': "root",
'PASSWORD': "さっき設定したパスワード",
'HOST': "localhost",
'PORT': '3306',
}
}
最後にマイグレーションで完了
この記事が気に入ったらサポートをしてみませんか?