質問編集履歴
1
追記記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
Dockerで動かしているMySQLに接続ができず、以下エラーが表示されてしまいます
|
2
2
|
|
3
|
+
MYSQLのバージョンは5.7.3
|
4
|
+
|
5
|
+
PHPは5.16かと思われます
|
6
|
+
|
3
7
|
### 発生している問題・エラーメッセージ
|
4
8
|
|
5
9
|
|
@@ -10,7 +14,7 @@
|
|
10
14
|
|
11
15
|
|
12
16
|
|
13
|
-
Message: mysqli::real_connect(): (HY000/1045): Access denied for user '
|
17
|
+
Message: mysqli::real_connect(): (HY000/1045): Access denied for user 'testuser'@'172.18.0.15' (using password: YES)
|
14
18
|
|
15
19
|
|
16
20
|
|
@@ -72,6 +76,862 @@
|
|
72
76
|
|
73
77
|
|
74
78
|
|
79
|
+
その他
|
80
|
+
|
81
|
+
docker-compose.yml
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
version: '2'
|
86
|
+
|
87
|
+
services:
|
88
|
+
|
89
|
+
db_data:
|
90
|
+
|
91
|
+
image: busybox
|
92
|
+
|
93
|
+
volumes:
|
94
|
+
|
95
|
+
- /var/lib/mysql
|
96
|
+
|
97
|
+
mysql:
|
98
|
+
|
99
|
+
build: ./config/mysql/
|
100
|
+
|
101
|
+
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
|
102
|
+
|
103
|
+
environment:
|
104
|
+
|
105
|
+
MYSQL_ROOT_PASSWORD: root
|
106
|
+
|
107
|
+
MYSQL_DATABASE: "localdb"
|
108
|
+
|
109
|
+
MYSQL_USER: "localuser"
|
110
|
+
|
111
|
+
MYSQL_PASSWORD: "root"
|
112
|
+
|
113
|
+
TZ: "Asia/Tokyo"
|
114
|
+
|
115
|
+
ports:
|
116
|
+
|
117
|
+
- "3306:3306"
|
118
|
+
|
119
|
+
volumes:
|
120
|
+
|
121
|
+
- ./sql:/docker-entrypoint-initdb.d
|
122
|
+
|
123
|
+
volumes_from:
|
124
|
+
|
125
|
+
- db_data
|
126
|
+
|
127
|
+
container_name: local_mysql56_cc
|
128
|
+
|
129
|
+
networks:
|
130
|
+
|
131
|
+
default:
|
132
|
+
|
133
|
+
external:
|
134
|
+
|
135
|
+
name: common_link
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
DB_Driver.php(恐らくDB接続については、ここで設定しているかと思われます。かなり長文のため、最初のinitalizeのみ抜粋)
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
abstract class CI_DB_driver {
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
/**
|
150
|
+
|
151
|
+
* Data Source Name / Connect string
|
152
|
+
|
153
|
+
*
|
154
|
+
|
155
|
+
* @var string
|
156
|
+
|
157
|
+
*/
|
158
|
+
|
159
|
+
public $dsn;
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
/**
|
164
|
+
|
165
|
+
* Username
|
166
|
+
|
167
|
+
*
|
168
|
+
|
169
|
+
* @var string
|
170
|
+
|
171
|
+
*/
|
172
|
+
|
173
|
+
public $username;
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
/**
|
178
|
+
|
179
|
+
* Password
|
180
|
+
|
181
|
+
*
|
182
|
+
|
183
|
+
* @var string
|
184
|
+
|
185
|
+
*/
|
186
|
+
|
187
|
+
public $password;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
/**
|
192
|
+
|
193
|
+
* Hostname
|
194
|
+
|
195
|
+
*
|
196
|
+
|
197
|
+
* @var string
|
198
|
+
|
199
|
+
*/
|
200
|
+
|
201
|
+
public $hostname;
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
/**
|
206
|
+
|
207
|
+
* Database name
|
208
|
+
|
209
|
+
*
|
210
|
+
|
211
|
+
* @var string
|
212
|
+
|
213
|
+
*/
|
214
|
+
|
215
|
+
public $database;
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
/**
|
220
|
+
|
221
|
+
* Database driver
|
222
|
+
|
223
|
+
*
|
224
|
+
|
225
|
+
* @var string
|
226
|
+
|
227
|
+
*/
|
228
|
+
|
229
|
+
public $dbdriver = 'mysqli';
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
/**
|
234
|
+
|
235
|
+
* Sub-driver
|
236
|
+
|
237
|
+
*
|
238
|
+
|
239
|
+
* @used-by CI_DB_pdo_driver
|
240
|
+
|
241
|
+
* @var string
|
242
|
+
|
243
|
+
*/
|
244
|
+
|
245
|
+
public $subdriver;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
/**
|
250
|
+
|
251
|
+
* Table prefix
|
252
|
+
|
253
|
+
*
|
254
|
+
|
255
|
+
* @var string
|
256
|
+
|
257
|
+
*/
|
258
|
+
|
259
|
+
public $dbprefix = '';
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
/**
|
264
|
+
|
265
|
+
* Character set
|
266
|
+
|
267
|
+
*
|
268
|
+
|
269
|
+
* @var string
|
270
|
+
|
271
|
+
*/
|
272
|
+
|
273
|
+
public $char_set = 'utf8';
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
/**
|
278
|
+
|
279
|
+
* Collation
|
280
|
+
|
281
|
+
*
|
282
|
+
|
283
|
+
* @var string
|
284
|
+
|
285
|
+
*/
|
286
|
+
|
287
|
+
public $dbcollat = 'utf8_general_ci';
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
/**
|
292
|
+
|
293
|
+
* Encryption flag/data
|
294
|
+
|
295
|
+
*
|
296
|
+
|
297
|
+
* @var mixed
|
298
|
+
|
299
|
+
*/
|
300
|
+
|
301
|
+
public $encrypt = FALSE;
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
/**
|
306
|
+
|
307
|
+
* Swap Prefix
|
308
|
+
|
309
|
+
*
|
310
|
+
|
311
|
+
* @var string
|
312
|
+
|
313
|
+
*/
|
314
|
+
|
315
|
+
public $swap_pre = '';
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
/**
|
320
|
+
|
321
|
+
* Database port
|
322
|
+
|
323
|
+
*
|
324
|
+
|
325
|
+
* @var int
|
326
|
+
|
327
|
+
*/
|
328
|
+
|
329
|
+
public $port = '';
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
/**
|
334
|
+
|
335
|
+
* Persistent connection flag
|
336
|
+
|
337
|
+
*
|
338
|
+
|
339
|
+
* @var bool
|
340
|
+
|
341
|
+
*/
|
342
|
+
|
343
|
+
public $pconnect = FALSE;
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
/**
|
348
|
+
|
349
|
+
* Connection ID
|
350
|
+
|
351
|
+
*
|
352
|
+
|
353
|
+
* @var object|resource
|
354
|
+
|
355
|
+
*/
|
356
|
+
|
357
|
+
public $conn_id = FALSE;
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
/**
|
362
|
+
|
363
|
+
* Result ID
|
364
|
+
|
365
|
+
*
|
366
|
+
|
367
|
+
* @var object|resource
|
368
|
+
|
369
|
+
*/
|
370
|
+
|
371
|
+
public $result_id = FALSE;
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
/**
|
376
|
+
|
377
|
+
* Debug flag
|
378
|
+
|
379
|
+
*
|
380
|
+
|
381
|
+
* Whether to display error messages.
|
382
|
+
|
383
|
+
*
|
384
|
+
|
385
|
+
* @var bool
|
386
|
+
|
387
|
+
*/
|
388
|
+
|
389
|
+
public $db_debug = FALSE;
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
/**
|
394
|
+
|
395
|
+
* Benchmark time
|
396
|
+
|
397
|
+
*
|
398
|
+
|
399
|
+
* @var int
|
400
|
+
|
401
|
+
*/
|
402
|
+
|
403
|
+
public $benchmark = 0;
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
/**
|
408
|
+
|
409
|
+
* Executed queries count
|
410
|
+
|
411
|
+
*
|
412
|
+
|
413
|
+
* @var int
|
414
|
+
|
415
|
+
*/
|
416
|
+
|
417
|
+
public $query_count = 0;
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
/**
|
422
|
+
|
423
|
+
* Bind marker
|
424
|
+
|
425
|
+
*
|
426
|
+
|
427
|
+
* Character used to identify values in a prepared statement.
|
428
|
+
|
429
|
+
*
|
430
|
+
|
431
|
+
* @var string
|
432
|
+
|
433
|
+
*/
|
434
|
+
|
435
|
+
public $bind_marker = '?';
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
/**
|
440
|
+
|
441
|
+
* Save queries flag
|
442
|
+
|
443
|
+
*
|
444
|
+
|
445
|
+
* Whether to keep an in-memory history of queries for debugging purposes.
|
446
|
+
|
447
|
+
*
|
448
|
+
|
449
|
+
* @var bool
|
450
|
+
|
451
|
+
*/
|
452
|
+
|
453
|
+
public $save_queries = TRUE;
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
/**
|
458
|
+
|
459
|
+
* Queries list
|
460
|
+
|
461
|
+
*
|
462
|
+
|
463
|
+
* @see CI_DB_driver::$save_queries
|
464
|
+
|
465
|
+
* @var string[]
|
466
|
+
|
467
|
+
*/
|
468
|
+
|
469
|
+
public $queries = array();
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
/**
|
474
|
+
|
475
|
+
* Query times
|
476
|
+
|
477
|
+
*
|
478
|
+
|
479
|
+
* A list of times that queries took to execute.
|
480
|
+
|
481
|
+
*
|
482
|
+
|
483
|
+
* @var array
|
484
|
+
|
485
|
+
*/
|
486
|
+
|
487
|
+
public $query_times = array();
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
/**
|
492
|
+
|
493
|
+
* Data cache
|
494
|
+
|
495
|
+
*
|
496
|
+
|
497
|
+
* An internal generic value cache.
|
498
|
+
|
499
|
+
*
|
500
|
+
|
501
|
+
* @var array
|
502
|
+
|
503
|
+
*/
|
504
|
+
|
505
|
+
public $data_cache = array();
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
/**
|
510
|
+
|
511
|
+
* Transaction enabled flag
|
512
|
+
|
513
|
+
*
|
514
|
+
|
515
|
+
* @var bool
|
516
|
+
|
517
|
+
*/
|
518
|
+
|
519
|
+
public $trans_enabled = TRUE;
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
/**
|
524
|
+
|
525
|
+
* Strict transaction mode flag
|
526
|
+
|
527
|
+
*
|
528
|
+
|
529
|
+
* @var bool
|
530
|
+
|
531
|
+
*/
|
532
|
+
|
533
|
+
public $trans_strict = TRUE;
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
/**
|
538
|
+
|
539
|
+
* Transaction depth level
|
540
|
+
|
541
|
+
*
|
542
|
+
|
543
|
+
* @var int
|
544
|
+
|
545
|
+
*/
|
546
|
+
|
547
|
+
protected $_trans_depth = 0;
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
/**
|
552
|
+
|
553
|
+
* Transaction status flag
|
554
|
+
|
555
|
+
*
|
556
|
+
|
557
|
+
* Used with transactions to determine if a rollback should occur.
|
558
|
+
|
559
|
+
*
|
560
|
+
|
561
|
+
* @var bool
|
562
|
+
|
563
|
+
*/
|
564
|
+
|
565
|
+
protected $_trans_status = TRUE;
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
/**
|
570
|
+
|
571
|
+
* Transaction failure flag
|
572
|
+
|
573
|
+
*
|
574
|
+
|
575
|
+
* Used with transactions to determine if a transaction has failed.
|
576
|
+
|
577
|
+
*
|
578
|
+
|
579
|
+
* @var bool
|
580
|
+
|
581
|
+
*/
|
582
|
+
|
583
|
+
protected $_trans_failure = FALSE;
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
/**
|
588
|
+
|
589
|
+
* Cache On flag
|
590
|
+
|
591
|
+
*
|
592
|
+
|
593
|
+
* @var bool
|
594
|
+
|
595
|
+
*/
|
596
|
+
|
597
|
+
public $cache_on = FALSE;
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
/**
|
602
|
+
|
603
|
+
* Cache directory path
|
604
|
+
|
605
|
+
*
|
606
|
+
|
607
|
+
* @var bool
|
608
|
+
|
609
|
+
*/
|
610
|
+
|
611
|
+
public $cachedir = '';
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
/**
|
616
|
+
|
617
|
+
* Cache auto-delete flag
|
618
|
+
|
619
|
+
*
|
620
|
+
|
621
|
+
* @var bool
|
622
|
+
|
623
|
+
*/
|
624
|
+
|
625
|
+
public $cache_autodel = FALSE;
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
/**
|
630
|
+
|
631
|
+
* DB Cache object
|
632
|
+
|
633
|
+
*
|
634
|
+
|
635
|
+
* @see CI_DB_cache
|
636
|
+
|
637
|
+
* @var object
|
638
|
+
|
639
|
+
*/
|
640
|
+
|
641
|
+
public $CACHE;
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
/**
|
646
|
+
|
647
|
+
* Protect identifiers flag
|
648
|
+
|
649
|
+
*
|
650
|
+
|
651
|
+
* @var bool
|
652
|
+
|
653
|
+
*/
|
654
|
+
|
655
|
+
protected $_protect_identifiers = TRUE;
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
/**
|
660
|
+
|
661
|
+
* List of reserved identifiers
|
662
|
+
|
663
|
+
*
|
664
|
+
|
665
|
+
* Identifiers that must NOT be escaped.
|
666
|
+
|
667
|
+
*
|
668
|
+
|
669
|
+
* @var string[]
|
670
|
+
|
671
|
+
*/
|
672
|
+
|
673
|
+
protected $_reserved_identifiers = array('*');
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
/**
|
678
|
+
|
679
|
+
* Identifier escape character
|
680
|
+
|
681
|
+
*
|
682
|
+
|
683
|
+
* @var string
|
684
|
+
|
685
|
+
*/
|
686
|
+
|
687
|
+
protected $_escape_char = '"';
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
/**
|
692
|
+
|
693
|
+
* ESCAPE statement string
|
694
|
+
|
695
|
+
*
|
696
|
+
|
697
|
+
* @var string
|
698
|
+
|
699
|
+
*/
|
700
|
+
|
701
|
+
protected $_like_escape_str = " ESCAPE '%s' ";
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
/**
|
706
|
+
|
707
|
+
* ESCAPE character
|
708
|
+
|
709
|
+
*
|
710
|
+
|
711
|
+
* @var string
|
712
|
+
|
713
|
+
*/
|
714
|
+
|
715
|
+
protected $_like_escape_chr = '!';
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
/**
|
720
|
+
|
721
|
+
* ORDER BY random keyword
|
722
|
+
|
723
|
+
*
|
724
|
+
|
725
|
+
* @var array
|
726
|
+
|
727
|
+
*/
|
728
|
+
|
729
|
+
protected $_random_keyword = array('RAND()', 'RAND(%d)');
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+
/**
|
734
|
+
|
735
|
+
* COUNT string
|
736
|
+
|
737
|
+
*
|
738
|
+
|
739
|
+
* @used-by CI_DB_driver::count_all()
|
740
|
+
|
741
|
+
* @used-by CI_DB_query_builder::count_all_results()
|
742
|
+
|
743
|
+
*
|
744
|
+
|
745
|
+
* @var string
|
746
|
+
|
747
|
+
*/
|
748
|
+
|
749
|
+
protected $_count_string = 'SELECT COUNT(*) AS ';
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
// --------------------------------------------------------------------
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
/**
|
758
|
+
|
759
|
+
* Class constructor
|
760
|
+
|
761
|
+
*
|
762
|
+
|
763
|
+
* @param array $params
|
764
|
+
|
765
|
+
* @return void
|
766
|
+
|
767
|
+
*/
|
768
|
+
|
769
|
+
public function __construct($params)
|
770
|
+
|
771
|
+
{
|
772
|
+
|
773
|
+
if (is_array($params))
|
774
|
+
|
775
|
+
{
|
776
|
+
|
777
|
+
foreach ($params as $key => $val)
|
778
|
+
|
779
|
+
{
|
780
|
+
|
781
|
+
$this->$key = $val;
|
782
|
+
|
783
|
+
}
|
784
|
+
|
785
|
+
}
|
786
|
+
|
787
|
+
|
788
|
+
|
789
|
+
log_message('info', 'Database Driver Class Initialized');
|
790
|
+
|
791
|
+
}
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
// --------------------------------------------------------------------
|
796
|
+
|
797
|
+
|
798
|
+
|
799
|
+
/**
|
800
|
+
|
801
|
+
* Initialize Database Settings
|
802
|
+
|
803
|
+
*
|
804
|
+
|
805
|
+
* @return bool
|
806
|
+
|
807
|
+
*/
|
808
|
+
|
809
|
+
public function initialize()
|
810
|
+
|
811
|
+
{
|
812
|
+
|
813
|
+
/* If an established connection is available, then there's
|
814
|
+
|
815
|
+
* no need to connect and select the database.
|
816
|
+
|
817
|
+
*
|
818
|
+
|
819
|
+
* Depending on the database driver, conn_id can be either
|
820
|
+
|
821
|
+
* boolean TRUE, a resource or an object.
|
822
|
+
|
823
|
+
*/
|
824
|
+
|
825
|
+
if ($this->conn_id)
|
826
|
+
|
827
|
+
{
|
828
|
+
|
829
|
+
return TRUE;
|
830
|
+
|
831
|
+
}
|
832
|
+
|
833
|
+
|
834
|
+
|
835
|
+
// ----------------------------------------------------------------
|
836
|
+
|
837
|
+
|
838
|
+
|
839
|
+
// Connect to the database and set the connection ID
|
840
|
+
|
841
|
+
$this->conn_id = $this->db_connect($this->pconnect);
|
842
|
+
|
843
|
+
|
844
|
+
|
845
|
+
// No connection resource? Check if there is a failover else throw an error
|
846
|
+
|
847
|
+
if ( ! $this->conn_id)
|
848
|
+
|
849
|
+
{
|
850
|
+
|
851
|
+
// Check if there is a failover set
|
852
|
+
|
853
|
+
if ( ! empty($this->failover) && is_array($this->failover))
|
854
|
+
|
855
|
+
{
|
856
|
+
|
857
|
+
// Go over all the failovers
|
858
|
+
|
859
|
+
foreach ($this->failover as $failover)
|
860
|
+
|
861
|
+
{
|
862
|
+
|
863
|
+
// Replace the current settings with those of the failover
|
864
|
+
|
865
|
+
foreach ($failover as $key => $val)
|
866
|
+
|
867
|
+
{
|
868
|
+
|
869
|
+
$this->$key = $val;
|
870
|
+
|
871
|
+
}
|
872
|
+
|
873
|
+
|
874
|
+
|
875
|
+
// Try to connect
|
876
|
+
|
877
|
+
$this->conn_id = $this->db_connect($this->pconnect);
|
878
|
+
|
879
|
+
|
880
|
+
|
881
|
+
// If a connection is made break the foreach loop
|
882
|
+
|
883
|
+
if ($this->conn_id)
|
884
|
+
|
885
|
+
{
|
886
|
+
|
887
|
+
break;
|
888
|
+
|
889
|
+
}
|
890
|
+
|
891
|
+
}
|
892
|
+
|
893
|
+
}
|
894
|
+
|
895
|
+
|
896
|
+
|
897
|
+
// We still don't have a connection?
|
898
|
+
|
899
|
+
if ( ! $this->conn_id)
|
900
|
+
|
901
|
+
{
|
902
|
+
|
903
|
+
log_message('error', 'Unable to connect to the database');
|
904
|
+
|
905
|
+
|
906
|
+
|
907
|
+
if ($this->db_debug)
|
908
|
+
|
909
|
+
{
|
910
|
+
|
911
|
+
$this->display_error('db_unable_to_connect');
|
912
|
+
|
913
|
+
}
|
914
|
+
|
915
|
+
|
916
|
+
|
917
|
+
return FALSE;
|
918
|
+
|
919
|
+
}
|
920
|
+
|
921
|
+
}
|
922
|
+
|
923
|
+
|
924
|
+
|
925
|
+
// Now we set the character set and that's all
|
926
|
+
|
927
|
+
return $this->db_set_charset($this->char_set);
|
928
|
+
|
929
|
+
}
|
930
|
+
|
931
|
+
|
932
|
+
|
933
|
+
```
|
934
|
+
|
75
935
|
### 試したこと
|
76
936
|
|
77
|
-
GRANT ALL ON test* to ‘
|
937
|
+
GRANT ALL ON test* to ‘testuser’@‘%’ IDENTIFIED BY ‘root’; でユーザー作成
|