반응형

Tasks

Check that there is a Cloud SQL instance
Check that there is a user database on the Cloud SQL instance
Check that the blog instance is authorized to access Cloud SQL
Check that wp-config.php points to the Cloud SQL instance
Check that the blog still responds to requests

 

1. Create Cloud SQL

 

2. MySql dump 를 export 한다.


참고 )
https://cloud.google.com/solutions/migrating-mysql-to-cloudsql-concept
https://cloud.google.com/sql/docs/mysql/import-export/creating-sqldump-csv#std

 

- 실행 명령어

mysqldump --databases [DATABASE_NAME] -h [INSTANCE_IP] -u [USERNAME] -p \
--hex-blob --skip-triggers --single-transaction --set-gtid-purged=OFF \
--ignore-table [VIEW_NAME1] [...] --default-character-set=utf8mb4 > [SQL_FILE].sql

 

- 조건 

The existing database for the blog is provided by MySQL running on the same server. 
The existing MySQL database is called wordpress and the user called blogadmin with password Password1*, which provides full access to that database.

 

- 실행

위 조건에 맞춰서 다음과 같이 실행을 한다. password 는 위 조건에서 처럼 Password1* 를 넣어주면 된다.

 

3. Cloud Bucket 생성 및 dump 를 gcs 로 복사한다.

 

export PROJECT_ID=$(gcloud info --format='value(config.project)')
gsutil mb gs://$PROJECT_ID
gsutil cp wordpress.sql gs://$PROJECT_ID

 

4. SQL 로 import 한다.

 

참고)

https://cloud.google.com/sql/docs/mysql/import-export/importing

 

명령어를 사용해도 되고 아래와 같이 화면에서 간단히 import 하면 더 편하다.

5. User 추가

 

SQL > Users 탭에서 Create user account 를 클릭한다.

blogadmin 계정을 만들어 준다.

다 된줄 알았는데 아래와 같이 에러가 나온다. ㅡㅡ;

SQL>Connections 탭을 가보면 아래 화면과 같이 Network 설정을 할 수 있다.

Network 설정을 해줘야 하는데 위와같은 range 를 만족해야 한다.

아래 사이트를 가면 쉽게 CIDR range 를 구할 수 있다.

https://www.ipaddressguide.com/cidr

 

CIDR to IPv4 Address Range Utility Tool | IPAddressGuide

Free IP address tool to translate IPv4 address range into CIDR (Classless Inter-Domain Routing) format and vice-versa.

www.ipaddressguide.com

6. wp-config.php 파일을 Cloud SQL Instance 를 사용하도록 수정해준다.

 

wp-config.php 파일에 아래 localhost 를 수정해 하고 주석을 해제 한다. (위치는 /var/www/html/wordpress)

** MySQL hostname

*/ define('DB_HOST', 'localhost');

 

 

7. 이제 재기동 한다. 

sudo service apache2 restart

 

728x90
반응형

+ Recent posts