質問編集履歴

8

修正

2020/09/14 04:43

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -360,4 +360,18 @@
360
360
 
361
361
  Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
362
362
 
363
+
364
+
365
+
366
+
367
+ ホストを替えた場合
368
+
369
+ Can't connect to MySQL server on 'fukusyun-2.local' (22)
370
+
371
+ Couldn't create 'Books_development' database. Please check your configuration.
372
+
373
+ rake aborted!
374
+
375
+ Mysql2::Error::ConnectionError: Can't connect to MySQL server on 'fukusyun-2.local' (22)
376
+
363
- ```
377
+ ```

7

修正

2020/09/14 04:43

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -339,3 +339,25 @@
339
339
  # socket: /var/lib/mysql/mysql.sock
340
340
 
341
341
  ```
342
+
343
+
344
+
345
+ ```
346
+
347
+ mysqlリスタート後
348
+
349
+
350
+
351
+ % docker-compose run web bundle exec rake db:create
352
+
353
+
354
+
355
+ Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
356
+
357
+ Couldn't create 'Books_development' database. Please check your configuration.
358
+
359
+ rake aborted!
360
+
361
+ Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
362
+
363
+ ```

6

修正

2020/09/14 04:38

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -270,6 +270,8 @@
270
270
 
271
271
  ```
272
272
 
273
+ 修正後エラー
274
+
273
275
  Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
274
276
 
275
277
  Couldn't create 'Books_development' database. Please check your configuration.

5

修正

2020/09/13 23:36

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -265,3 +265,75 @@
265
265
 
266
266
 
267
267
  ```
268
+
269
+
270
+
271
+ ```
272
+
273
+ Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
274
+
275
+ Couldn't create 'Books_development' database. Please check your configuration.
276
+
277
+ rake aborted!
278
+
279
+ Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
280
+
281
+ /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect'
282
+
283
+ ```
284
+
285
+ ```database
286
+
287
+
288
+
289
+ default: &default
290
+
291
+ adapter: mysql2
292
+
293
+ encoding: utf8
294
+
295
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
296
+
297
+ username: root
298
+
299
+ password: <%= ENV['DATABASE_PASSWORD'] %>
300
+
301
+ # socket: /tmp/mysql.sock
302
+
303
+
304
+
305
+ host: localhost
306
+
307
+
308
+
309
+ development:
310
+
311
+ <<: *default
312
+
313
+ database: Books_development
314
+
315
+
316
+
317
+ test:
318
+
319
+ <<: *default
320
+
321
+ database: Books_test
322
+
323
+
324
+
325
+ production:
326
+
327
+ <<: *default
328
+
329
+ database: Books_production
330
+
331
+
332
+
333
+ username: root
334
+
335
+ password: <%= ENV['DATABASE_PASSWORD'] %>
336
+
337
+ # socket: /var/lib/mysql/mysql.sock
338
+
339
+ ```

4

修正

2020/09/13 23:35

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -218,6 +218,18 @@
218
218
 
219
219
  ```
220
220
 
221
+ docker-compose down --rmi all --volumes
222
+
223
+
224
+
225
+ Books % docker-compose build
226
+
227
+
228
+
229
+ Books % docker-compose run web bundle exec rake db:create
230
+
231
+
232
+
221
233
  Creating books_db_1 ... done
222
234
 
223
235
  Creating books_web_run ... done

3

修正

2020/09/13 22:55

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -218,10 +218,38 @@
218
218
 
219
219
  ```
220
220
 
221
+ Creating books_db_1 ... done
222
+
223
+ Creating books_web_run ... done
224
+
225
+ Can't connect to MySQL server on 'fukusyun-2.local' (22)
226
+
227
+ Couldn't create 'Books_development' database. Please check your configuration.
228
+
229
+ rake aborted!
230
+
231
+ Mysql2::Error::ConnectionError: Can't connect to MySQL server on 'fukusyun-2.local' (22)
232
+
233
+ /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect'
234
+
235
+
236
+
237
+
238
+
221
- mysql> show databases
239
+ mysql> show variables like 'hostname';
240
+
222
-
241
+ +---------------+------------------+
242
+
243
+ | Variable_name | Value |
244
+
245
+ +---------------+------------------+
246
+
247
+ | hostname | fukusyun-2.local |
248
+
249
+ +---------------+------------------+
250
+
223
- -> SHOW DATABASES;
251
+ 1 row in set (0.00 sec)
224
-
225
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SHOW DATABASES' at line 2
252
+
226
-
253
+
254
+
227
- ```
255
+ ```

2

修正

2020/09/13 22:52

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -213,3 +213,15 @@
213
213
  ERROR! Failed to stop running server, so refusing to try to start.
214
214
 
215
215
  ```
216
+
217
+
218
+
219
+ ```
220
+
221
+ mysql> show databases
222
+
223
+ -> SHOW DATABASES;
224
+
225
+ ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SHOW DATABASES' at line 2
226
+
227
+ ```

1

修正

2020/09/13 22:44

投稿

tomsuma
tomsuma

スコア38

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
 
12
12
 
13
+ docker-compose run web bundle exec rake db:create
14
+
15
+ しても同じようなエラーが出ます
16
+
17
+
18
+
19
+ ```
20
+
21
+ Mysql2::Error::ConnectionError: Can't connect to MySQL server on 'db' (115)
22
+
23
+ ```
24
+
13
25
  ```dockercompose
14
26
 
15
27
  version: '3'
@@ -66,6 +78,58 @@
66
78
 
67
79
  ```
68
80
 
81
+
82
+
83
+ ```dockerfile
84
+
85
+ FROM ruby:2.6.5
86
+
87
+
88
+
89
+
90
+
91
+ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
92
+
93
+ && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
94
+
95
+
96
+
97
+ RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs yarn
98
+
99
+
100
+
101
+ WORKDIR /Books/
102
+
103
+ COPY Gemfile ./Gemfile
104
+
105
+ COPY Gemfile.lock ./Gemfile.lock
106
+
107
+ RUN gem install bundler
108
+
109
+ RUN bundle install
110
+
111
+ COPY . /Books/
112
+
113
+
114
+
115
+ # Add a script to be executed every time the container starts.
116
+
117
+ COPY entrypoint.sh /usr/bin/
118
+
119
+ RUN chmod +x /usr/bin/entrypoint.sh
120
+
121
+ ENTRYPOINT ["entrypoint.sh"]
122
+
123
+ EXPOSE 3000
124
+
125
+
126
+
127
+ # Start the main process.
128
+
129
+ CMD ["rails", "server", "-b", "0.0.0.0"]
130
+
131
+ ```
132
+
69
133
  ```database
70
134
 
71
135