質問編集履歴

10

修正

2020/09/17 06:24

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  お世話になっております。
2
2
 
3
- 現在、LuggageMGTというアプリを本番環境で動かそうと試みています。
3
+ 現在、LuggageMGTというアプリ作成しています。
4
4
 
5
5
 
6
6
 
@@ -24,6 +24,10 @@
24
24
 
25
25
 
26
26
 
27
+
28
+
29
+
30
+
27
31
  #実行したこと
28
32
 
29
33
  /tmp/mysql.sockが存在するか下記コマンドで確認しました
@@ -56,6 +60,18 @@
56
60
 
57
61
 
58
62
 
63
+ きちんとファイルは存在するのに、
64
+
65
+ ```
66
+
67
+ (2 "No such file or directory")
68
+
69
+ ```
70
+
71
+ と出る理由も分かりません。
72
+
73
+
74
+
59
75
 
60
76
 
61
77
 

9

修正

2020/09/17 06:24

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  ```
32
32
 
33
- %mysql_config --socket
33
+ % mysql_config --socket
34
34
 
35
35
  /tmp/mysql.sock
36
36
 
@@ -42,7 +42,15 @@
42
42
 
43
43
  ```
44
44
 
45
- mysql.server restart
45
+ % mysql.server restart
46
+
47
+ Shutting down MySQL
48
+
49
+ .. SUCCESS!
50
+
51
+ Starting MySQL
52
+
53
+ .. SUCCESS!
46
54
 
47
55
  ```
48
56
 

8

修正

2020/09/17 06:22

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  ```
44
44
 
45
- sudo mysql.server start
45
+ mysql.server restart
46
46
 
47
47
  ```
48
48
 

7

修正

2020/09/17 06:21

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -26,17 +26,19 @@
26
26
 
27
27
  #実行したこと
28
28
 
29
- /tmp/mysql.sockが存在するか確認するめ、
29
+ /tmp/mysql.sockが存在するか下記コマンドで確認しまし
30
-
30
+
31
- ```
31
+ ```
32
-
32
+
33
- mysql_config --socket
33
+ %mysql_config --socket
34
+
34
-
35
+ /tmp/mysql.sock
36
+
35
- ```
37
+ ```
36
-
37
-
38
-
38
+
39
+
40
+
39
- 打ち、存在は確認できました。
41
+ 下記コマンドでMySQL再起動させました。
40
42
 
41
43
  ```
42
44
 
@@ -44,7 +46,7 @@
44
46
 
45
47
  ```
46
48
 
47
- でMySQLを再起動させました。
49
+
48
50
 
49
51
 
50
52
 

6

修正

2020/09/17 06:20

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -38,7 +38,13 @@
38
38
 
39
39
  を打ち、存在は確認できました。
40
40
 
41
+ ```
42
+
41
- しかし、なぜこの様なエラーが出るかが分かりません。
43
+ sudo mysql.server start
44
+
45
+ ```
46
+
47
+ でMySQLを再起動させました。
42
48
 
43
49
 
44
50
 

5

修正

2020/09/17 06:16

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
@@ -1 +1 @@
1
- 本番環境にてMysql2::Error::ConnectionError: Unknown MySQL server host 'db' (25)エラー
1
+ Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 "No such file or directorエラー
test CHANGED
File without changes

4

修正

2020/09/17 06:12

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -10,31 +10,11 @@
10
10
 
11
11
  # 解決したいこと、エラー
12
12
 
13
- ec2-userのターミナルにて、
13
+ ローカルのターミナルにて、docker-compose upをすると、
14
-
14
+
15
- ```
15
+ ```
16
-
17
- rails db:create RAILS_ENV=production
16
+
18
-
19
- ```
20
-
21
- を打つと、
22
-
23
- ```
24
-
25
- Unknown MySQL server host 'db' (25)
26
-
27
- Couldn't create 'LuggageMGT_production' database. Please check your configuration.
17
+ Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 "No such file or directory")
28
-
29
- rails aborted!
30
-
31
- Mysql2::Error::ConnectionError: Unknown MySQL server host 'db' (25)
32
-
33
- bin/rails:4:in `<main>'
34
-
35
- Tasks: TOP => db:create
36
-
37
- (See full trace by running task with --trace)
38
18
 
39
19
  ```
40
20
 
@@ -46,39 +26,25 @@
46
26
 
47
27
  #実行したこと
48
28
 
49
- mysqlが起動していない可能性があと仮説を立て
29
+ /tmp/mysql.sock存在すか確認するため
50
-
30
+
51
- ```
31
+ ```
52
-
32
+
53
- sudo service mysqld start
33
+ mysql_config --socket
54
-
34
+
55
- ```
35
+ ```
56
-
57
-
58
-
59
- を打ち、再度試みましたがエラー文は変わりませんでした。
36
+
60
-
61
-
62
-
63
- ローカルでは、
37
+
64
-
65
- ```
38
+
66
-
67
- docker-compose run web rails db:create
68
-
69
- docker-compose run web rails db:migrate
70
-
71
- ```
72
-
73
-
74
-
75
- テーダベース作成できました。
39
+ 打ち存在確認できました。
76
-
40
+
77
- (関係あるか分かりませんが、docker-compose downをすると、upした後再度rails db:createからし直さなければいけない状況です)
41
+ しかし、なぜこの様なエラーが出るか分かりません。
78
-
79
-
80
-
42
+
43
+
44
+
45
+
46
+
81
- 下記かr該当してそうなファイルを記述致します。
47
+ 下記該当してそうなファイルを記述致します。
82
48
 
83
49
  まだまだ知識が甘く、変なところもあるかもしれないです。よろしくお願い致します。
84
50
 
@@ -88,9 +54,105 @@
88
54
 
89
55
  ```
90
56
 
57
+ # MySQL. Versions 5.1.10 and up are supported.
58
+
91
- #省略
59
+ #
60
+
92
-
61
+ # Install the MySQL driver
62
+
93
-
63
+ # gem install mysql2
64
+
65
+ #
66
+
67
+ # Ensure the MySQL gem is defined in your Gemfile
68
+
69
+ # gem 'mysql2'
70
+
71
+ #
72
+
73
+ # And be sure to use new-style password hashing:
74
+
75
+ # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
76
+
77
+ #
78
+
79
+ default: &default
80
+
81
+ adapter: mysql2
82
+
83
+ encoding: utf8
84
+
85
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
86
+
87
+ username: root
88
+
89
+ password: password
90
+
91
+ host: localhost
92
+
93
+ socket: /tmp/mysql.sock
94
+
95
+
96
+
97
+ development:
98
+
99
+ <<: *default
100
+
101
+ database: LuggageMGT_development
102
+
103
+
104
+
105
+ # Warning: The database defined as "test" will be erased and
106
+
107
+ # re-generated from your development database when you run "rake".
108
+
109
+ # Do not set this db to the same as development or production.
110
+
111
+ test:
112
+
113
+ <<: *default
114
+
115
+ database: LuggageMGT_test
116
+
117
+
118
+
119
+ # As with config/secrets.yml, you never want to store sensitive information,
120
+
121
+ # like your database password, in your source code. If your source code is
122
+
123
+ # ever seen by anyone, they now have access to your database.
124
+
125
+ #
126
+
127
+ # Instead, provide the password as a unix environment variable when you boot
128
+
129
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
130
+
131
+ # for a full rundown on how to provide these environment variables in a
132
+
133
+ # production deployment.
134
+
135
+ #
136
+
137
+ # On Heroku and other platform providers, you may have a full connection URL
138
+
139
+ # available as an environment variable. For example:
140
+
141
+ #
142
+
143
+ # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
144
+
145
+ #
146
+
147
+ # You can use this database configuration with:
148
+
149
+ #
150
+
151
+ # production:
152
+
153
+ # url: <%= ENV['DATABASE_URL'] %>
154
+
155
+ #
94
156
 
95
157
  production:
96
158
 
@@ -102,278 +164,278 @@
102
164
 
103
165
  password: <%= ENV['DATABASE_PASSWORD'] %>
104
166
 
167
+ socket: /tmp/mysql.sock
168
+
169
+ ```
170
+
171
+ docker-compose.yml
172
+
173
+ ```
174
+
175
+ version: '3'
176
+
177
+
178
+
179
+ services:
180
+
181
+ web:
182
+
183
+ build: .
184
+
185
+ ports:
186
+
187
+ - "3000:3000"
188
+
189
+ tty: true
190
+
191
+ command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
192
+
193
+ volumes:
194
+
195
+ - .:/app_name
196
+
197
+ depends_on:
198
+
199
+ - db
200
+
201
+
202
+
203
+ db:
204
+
205
+ image: mysql:5.6.47
206
+
207
+ environment:
208
+
209
+ MYSQL_ROOT_PASSWORD: password
210
+
211
+ MYSQL_DATABASE: root
212
+
213
+ ports:
214
+
215
+ - "3306:3306"
216
+
217
+ volumes:
218
+
219
+ - ./tmp/db:/var/lib/mysql/data
220
+
221
+ volumes:
222
+
223
+ bundle:
224
+
225
+ mysql_data:
226
+
227
+ ```
228
+
229
+
230
+
231
+ dockerfile
232
+
233
+ ```
234
+
235
+ FROM ruby:2.5.3
236
+
237
+ RUN apt-get update -qq && \
238
+
239
+ apt-get install -y build-essential \
240
+
241
+ libpq-dev \
242
+
243
+ nodejs
244
+
245
+
246
+
247
+ RUN mkdir /app_name
248
+
249
+ ENV APP_ROOT /app_name
250
+
251
+ WORKDIR $APP_ROOT
252
+
253
+
254
+
255
+ ADD ./Gemfile $APP_ROOT/Gemfile
256
+
257
+ ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock
258
+
259
+
260
+
261
+ RUN bundle install
262
+
263
+ ADD . $APP_ROOT
264
+
265
+ ```
266
+
267
+
268
+
269
+ circleci/config.yml
270
+
271
+ ```
272
+
273
+ version: 2.1
274
+
275
+ orbs:
276
+
277
+ ruby: circleci/ruby@0.1.2
278
+
279
+
280
+
281
+ jobs:
282
+
283
+ build:
284
+
285
+ docker:
286
+
287
+ - image: circleci/ruby:2.5.3-stretch-node
288
+
289
+ - image: circleci/mysql:5.6.47
290
+
291
+ environment:
292
+
293
+ MYSQL_ROOT_PASSWORD: "password"
294
+
295
+ MYSQL_ROOT_HOST: "%"
296
+
297
+ working_directory: ~/LuggageMTG
298
+
299
+
300
+
301
+ executor: ruby/default
302
+
303
+ steps:
304
+
305
+ - checkout
306
+
307
+ - run:
308
+
309
+ name: Which bundler?
310
+
311
+ command: bundle -v
312
+
313
+ - ruby/bundle-install
314
+
315
+
316
+
317
+ ```
318
+
319
+
320
+
321
+ 追記です。
322
+
323
+ database.ymlです。
324
+
325
+ ```
326
+
327
+ # MySQL. Versions 5.1.10 and up are supported.
328
+
329
+ #
330
+
331
+ # Install the MySQL driver
332
+
333
+ # gem install mysql2
334
+
335
+ #
336
+
337
+ # Ensure the MySQL gem is defined in your Gemfile
338
+
339
+ # gem 'mysql2'
340
+
341
+ #
342
+
343
+ # And be sure to use new-style password hashing:
344
+
345
+ # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
346
+
347
+ #
348
+
349
+ default: &default
350
+
351
+ adapter: mysql2
352
+
353
+ encoding: utf8
354
+
355
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
356
+
357
+ username: root
358
+
359
+ password: password
360
+
361
+ host: localhost
362
+
363
+
364
+
365
+ development:
366
+
367
+ <<: *default
368
+
369
+ database: LuggageMGT_development
370
+
371
+
372
+
373
+ # Warning: The database defined as "test" will be erased and
374
+
375
+ # re-generated from your development database when you run "rake".
376
+
377
+ # Do not set this db to the same as development or production.
378
+
379
+ test:
380
+
381
+ <<: *default
382
+
383
+ database: LuggageMGT_test
384
+
385
+
386
+
387
+ # As with config/secrets.yml, you never want to store sensitive information,
388
+
389
+ # like your database password, in your source code. If your source code is
390
+
391
+ # ever seen by anyone, they now have access to your database.
392
+
393
+ #
394
+
395
+ # Instead, provide the password as a unix environment variable when you boot
396
+
397
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
398
+
399
+ # for a full rundown on how to provide these environment variables in a
400
+
401
+ # production deployment.
402
+
403
+ #
404
+
405
+ # On Heroku and other platform providers, you may have a full connection URL
406
+
407
+ # available as an environment variable. For example:
408
+
409
+ #
410
+
411
+ # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
412
+
413
+ #
414
+
415
+ # You can use this database configuration with:
416
+
417
+ #
418
+
419
+ # production:
420
+
421
+ # url: <%= ENV['DATABASE_URL'] %>
422
+
423
+ #
424
+
425
+ production:
426
+
427
+ <<: *default
428
+
429
+ database: LuggageMGT_production
430
+
431
+ username: root
432
+
433
+ password: <%= ENV['DATABASE_PASSWORD'] %>
434
+
105
435
  socket: /var/lib/mysql/mysql.sock
106
436
 
107
437
  ```
108
438
 
109
- docker-compose.yml
110
-
111
- ```
112
-
113
- version: '3'
114
-
115
-
116
-
117
- services:
118
-
119
- web:
120
-
121
- build: .
122
-
123
- ports:
124
-
125
- - "3000:3000"
126
-
127
- tty: true
128
-
129
- command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
130
-
131
- volumes:
132
-
133
- - .:/app_name
134
-
135
- depends_on:
136
-
137
- - db
138
-
139
-
140
-
141
- db:
142
-
143
- image: mysql:5.6.47
144
-
145
- environment:
146
-
147
- MYSQL_ROOT_PASSWORD: password
148
-
149
- MYSQL_DATABASE: root
150
-
151
- ports:
152
-
153
- - "3306:3306"
154
-
155
- volumes:
156
-
157
- - ./tmp/db:/var/lib/mysql/data
158
-
159
- volumes:
160
-
161
- bundle:
162
-
163
- mysql_data:
164
-
165
- ```
166
-
167
-
168
-
169
- dockerfile
170
-
171
- ```
172
-
173
- FROM ruby:2.5.3
174
-
175
- RUN apt-get update -qq && \
176
-
177
- apt-get install -y build-essential \
178
-
179
- libpq-dev \
180
-
181
- nodejs
182
-
183
-
184
-
185
- RUN mkdir /app_name
186
-
187
- ENV APP_ROOT /app_name
188
-
189
- WORKDIR $APP_ROOT
190
-
191
-
192
-
193
- ADD ./Gemfile $APP_ROOT/Gemfile
194
-
195
- ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock
196
-
197
-
198
-
199
- RUN bundle install
200
-
201
- ADD . $APP_ROOT
202
-
203
- ```
204
-
205
-
206
-
207
- circleci/config.yml
208
-
209
- ```
210
-
211
- version: 2.1
212
-
213
- orbs:
214
-
215
- ruby: circleci/ruby@0.1.2
216
-
217
-
218
-
219
- jobs:
220
-
221
- build:
222
-
223
- docker:
224
-
225
- - image: circleci/ruby:2.5.3-stretch-node
226
-
227
- - image: circleci/mysql:5.6.47
228
-
229
- environment:
230
-
231
- MYSQL_ROOT_PASSWORD: "password"
232
-
233
- MYSQL_ROOT_HOST: "%"
234
-
235
- working_directory: ~/LuggageMTG
236
-
237
-
238
-
239
- executor: ruby/default
240
-
241
- steps:
242
-
243
- - checkout
244
-
245
- - run:
246
-
247
- name: Which bundler?
248
-
249
- command: bundle -v
250
-
251
- - ruby/bundle-install
252
-
253
-
254
-
255
- ```
256
-
257
-
258
-
259
- 追記です。
260
-
261
- database.ymlです。
262
-
263
- ```
264
-
265
- # MySQL. Versions 5.1.10 and up are supported.
266
-
267
- #
268
-
269
- # Install the MySQL driver
270
-
271
- # gem install mysql2
272
-
273
- #
274
-
275
- # Ensure the MySQL gem is defined in your Gemfile
276
-
277
- # gem 'mysql2'
278
-
279
- #
280
-
281
- # And be sure to use new-style password hashing:
282
-
283
- # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
284
-
285
- #
286
-
287
- default: &default
288
-
289
- adapter: mysql2
290
-
291
- encoding: utf8
292
-
293
- pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
294
-
295
- username: root
296
-
297
- password: password
298
-
299
- host: localhost
300
-
301
-
302
-
303
- development:
304
-
305
- <<: *default
306
-
307
- database: LuggageMGT_development
308
-
309
-
310
-
311
- # Warning: The database defined as "test" will be erased and
312
-
313
- # re-generated from your development database when you run "rake".
314
-
315
- # Do not set this db to the same as development or production.
316
-
317
- test:
318
-
319
- <<: *default
320
-
321
- database: LuggageMGT_test
322
-
323
-
324
-
325
- # As with config/secrets.yml, you never want to store sensitive information,
326
-
327
- # like your database password, in your source code. If your source code is
328
-
329
- # ever seen by anyone, they now have access to your database.
330
-
331
- #
332
-
333
- # Instead, provide the password as a unix environment variable when you boot
334
-
335
- # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
336
-
337
- # for a full rundown on how to provide these environment variables in a
338
-
339
- # production deployment.
340
-
341
- #
342
-
343
- # On Heroku and other platform providers, you may have a full connection URL
344
-
345
- # available as an environment variable. For example:
346
-
347
- #
348
-
349
- # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
350
-
351
- #
352
-
353
- # You can use this database configuration with:
354
-
355
- #
356
-
357
- # production:
358
-
359
- # url: <%= ENV['DATABASE_URL'] %>
360
-
361
- #
362
-
363
- production:
364
-
365
- <<: *default
366
-
367
- database: LuggageMGT_production
368
-
369
- username: root
370
-
371
- password: <%= ENV['DATABASE_PASSWORD'] %>
372
-
373
- socket: /var/lib/mysql/mysql.sock
374
-
375
- ```
376
-
377
439
 
378
440
 
379
441
  host: dbをlocalhostにしたりしたのですが、現状何も変わっておりません。

3

修正

2020/09/17 06:11

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -253,3 +253,129 @@
253
253
 
254
254
 
255
255
  ```
256
+
257
+
258
+
259
+ 追記です。
260
+
261
+ database.ymlです。
262
+
263
+ ```
264
+
265
+ # MySQL. Versions 5.1.10 and up are supported.
266
+
267
+ #
268
+
269
+ # Install the MySQL driver
270
+
271
+ # gem install mysql2
272
+
273
+ #
274
+
275
+ # Ensure the MySQL gem is defined in your Gemfile
276
+
277
+ # gem 'mysql2'
278
+
279
+ #
280
+
281
+ # And be sure to use new-style password hashing:
282
+
283
+ # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
284
+
285
+ #
286
+
287
+ default: &default
288
+
289
+ adapter: mysql2
290
+
291
+ encoding: utf8
292
+
293
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
294
+
295
+ username: root
296
+
297
+ password: password
298
+
299
+ host: localhost
300
+
301
+
302
+
303
+ development:
304
+
305
+ <<: *default
306
+
307
+ database: LuggageMGT_development
308
+
309
+
310
+
311
+ # Warning: The database defined as "test" will be erased and
312
+
313
+ # re-generated from your development database when you run "rake".
314
+
315
+ # Do not set this db to the same as development or production.
316
+
317
+ test:
318
+
319
+ <<: *default
320
+
321
+ database: LuggageMGT_test
322
+
323
+
324
+
325
+ # As with config/secrets.yml, you never want to store sensitive information,
326
+
327
+ # like your database password, in your source code. If your source code is
328
+
329
+ # ever seen by anyone, they now have access to your database.
330
+
331
+ #
332
+
333
+ # Instead, provide the password as a unix environment variable when you boot
334
+
335
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
336
+
337
+ # for a full rundown on how to provide these environment variables in a
338
+
339
+ # production deployment.
340
+
341
+ #
342
+
343
+ # On Heroku and other platform providers, you may have a full connection URL
344
+
345
+ # available as an environment variable. For example:
346
+
347
+ #
348
+
349
+ # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
350
+
351
+ #
352
+
353
+ # You can use this database configuration with:
354
+
355
+ #
356
+
357
+ # production:
358
+
359
+ # url: <%= ENV['DATABASE_URL'] %>
360
+
361
+ #
362
+
363
+ production:
364
+
365
+ <<: *default
366
+
367
+ database: LuggageMGT_production
368
+
369
+ username: root
370
+
371
+ password: <%= ENV['DATABASE_PASSWORD'] %>
372
+
373
+ socket: /var/lib/mysql/mysql.sock
374
+
375
+ ```
376
+
377
+
378
+
379
+ host: dbをlocalhostにしたりしたのですが、現状何も変わっておりません。
380
+
381
+ お力を貸してください....。

2

修正

2020/09/15 15:03

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -74,7 +74,7 @@
74
74
 
75
75
  をし、テーダベースは作成できました。
76
76
 
77
- (関係あるかは分かりませんが、docker-compose downをすると、upした後再度rails:dbcreateしなければいけない状況です。)
77
+ (関係あるかは分かりませんが、docker-compose downをすると、upした後再度rails db:createから直さなければいけない状況です。)
78
78
 
79
79
 
80
80
 

1

修正

2020/09/14 15:25

投稿

keisuke.F
keisuke.F

スコア19

test CHANGED
File without changes
test CHANGED
@@ -204,7 +204,7 @@
204
204
 
205
205
 
206
206
 
207
- circleCI/config.yml
207
+ circleci/config.yml
208
208
 
209
209
  ```
210
210