-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcages.txt
7790 lines (6881 loc) · 264 KB
/
cages.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Serving CAGES Data from Databases via ERDDAP
============================================
Steven K. Baum
v0.5, 2013-02-18
:doctype: book
:toc:
:icons:
:numbered!:
[preface]
Executive Summary
-----------------
Using MySQL/PostgreSQL and ERDDAP to Serve CAGES Data.
Preface
-------
The use MySQL with CAGES data.
:numbered:
Required Basic MySQL Commands and Information
---------------------------------------------
In the course of preparing tables within MySQL for export to ERDDAP,
we found the following MySQL commands, procedures and datatype
information most useful.
Login
~~~~~
-----
mysql -u root -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1274228
Server version: 5.5.27-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
-----
Database Commands
~~~~~~~~~~~~~~~~~
Check for Database Names
^^^^^^^^^^^^^^^^^^^^^^^^
-----
SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| CAGES |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.03 sec)
-----
Select a Database to Use
^^^^^^^^^^^^^^^^^^^^^^^^
-----
use CAGES;
-----
Table Commands
~~~~~~~~~~~~~~
Show the Tables in the Database
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
show TABLES;
+------------------------------------------+
| Tables_in_CAGES |
+------------------------------------------+
| Alabama_CPUE |
| Alabama_Gear |
| Alabama_Hydrological |
| Alabama_Lengths |
...
| Mississippi_Trawls |
| TMPTAB |
| Texas_Bays |
| Texas_CPUE |
| Texas_Hydrological |
| Texas_Lengths |
| Texas_Samples |
| Texas_Species |
| Texas_Stations |
| Texas_SubBays |
| Texas_Trawls |
| example |
+------------------------------------------+
64 rows in set (0.00 sec)
-----
Change a Table Name
^^^^^^^^^^^^^^^^^^^
Use backticks for names with spaces.
-----
rename table `Texas_CPUE` to Texas_CPUE;
-----
List Rows of Table
^^^^^^^^^^^^^^^^^^
-----
select * from Texas_SubBays;
-----
To limit the number of rows listed:
-----
select * from Texas_SubBays limit 5;
-----
Find Total Number of Rows in Table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
select count(*) from Texas_CPUE;
-----
Delete a Table
^^^^^^^^^^^^^^
-----
drop table Texas_CPUE_New;
-----
Clone a Table
^^^^^^^^^^^^^
First you recreate the structure of the table to be cloned, and then
you populate that structure.
-----
create table CAGES_Texas_IOOS_Biology_10 like CAGES_Texas_IOOS_Biology;
insert CAGES_Texas_IOOS_Biology_10 select * from CAGES_Texas_IOOS_Biology;
-----
Remove All Rows from a Table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This will delete all the data in the table and return the number
of rows deleted.
-----
delete from CAGES_Texas_IOOS_Biology_10;
-----
This will quickly delete all the data in the table.
-----
truncate table CAGES_Texas_IOOS_Biology_10;
-----
Create an Index for a Table
^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
create index name_index on table(name);
-----
Show the Index for a Table
^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
show index from Texas_Trawls;
-----
to obtain:
-----
+------------+------------+-------------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+-------------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Texas_Bays | 1 | Texas_Bays_Bay_Location | 1 | Bay_Location | A | 15 | NULL | NULL | YES | BTREE | | |
| Texas_Bays | 1 | Texas_Bays_Bay_Code | 1 | Bay_Code | A | 15 | NULL | NULL | YES | BTREE | | |
+------------+------------+-------------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)
-----
from a table where:
-----
describe Texas_Bays;
-----
yields:
-----
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| Bay_Code | int(11) | YES | MUL | NULL | |
| Bay_Location | varchar(255) | YES | MUL | NULL | |
+--------------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
-----
Column Commands
~~~~~~~~~~~~~~~
Add a Column to a Table
^^^^^^^^^^^^^^^^^^^^^^^
This is explained at:
http://www.tech-recipes.com/rx/378/add-a-column-to-an-existing-mysql-table/[http://www.tech-recipes.com/rx/378/add-a-column-to-an-existing-mysql-table/]
-----
alter table CAGES add longitude varchar(100) after latitude;
-----
List Columns in Table
^^^^^^^^^^^^^^^^^^^^^
-----
describe Texas_CPUE;
-----
Change a Column Name
^^^^^^^^^^^^^^^^^^^^
-----
alter table Texas_CPUE change `Bay Code` Bay_Code int(11);
-----
Change the Datatype in a Column
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
http://stackoverflow.com/questions/1356866/how-do-i-change-the-data-type-for-a-column-in-mysql[+http://stackoverflow.com/questions/1356866/how-do-i-change-the-data-type-for-a-column-in-mysql+]
You only have to specify the new datatype, e.g. INTEGER in the following:
-----
ALTER TABLE tablename MODIFY columnname INTEGER;
-----
or in the real world:
-----
alter table CAGES_Texas_Trawls_Lengths_IOOS_Standard modify minimumDepthInMeters double;
-----
Privileges
~~~~~~~~~~
Grant Database Privileges to a Remote User
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
grant all privileges on CAGES2.* to [email protected];
grant all privileges on CAGES2.* to [email protected] identified by 'password';
-----
List Users and Their Privileges
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
select user,host from mysql.user;
-----
Datatypes and Manipulations
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change a TIMESTAMP into a VARCHAR with String Modification
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
We want to change, e.g.
-----
2013-03-13 21:38:35
-----
into, e.g.
-----
2013-03-13T21:38:35Z
-----
First, we change the initial string from a TIMESTAMP variable
into a VARCHAR variable via:
-----
alter table CAGES_Texas_Trawls_Lengths_IOOS_Standard modify modified varchar(65);
-----
Then, we insert the T via:
-----
update CAGES_Texas_Trawls_Lengths_IOOS_Standard set modified = replace(modified,' ','T');
-----
Then, we append a Z to this string via:
-----
update CAGES_Texas_Trawls_Lengths_IOOS_Standard set modified = concat(modified,'Z');
-----
Prepend Days/Months/Years with Zeros
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----
ALTER TABLE `table` CHANGE `zip` `zip` CHAR(5); #changes type
UPDATE table SET `zip`=LPAD(`zip`, 5, '0'); #pads everything
-----
Data Types
^^^^^^^^^^
These are described at:
-----
http://www.htmlite.com/mysql003.php
-----
The *text* types are:
-----
CHAR( ) A fixed section from 0 to 255 characters long.
VARCHAR( ) A variable section from 0 to 255 characters long.
TINYTEXT A string with a maximum length of 255 characters.
TEXT A string with a maximum length of 65535 characters.
BLOB A string with a maximum length of 65535 characters.
MEDIUMTEXT A string with a maximum length of 16777215 characters.
MEDIUMBLOB A string with a maximum length of 16777215 characters.
LONGTEXT A string with a maximum length of 4294967295 characters.
LONGBLOB A string with a maximum length of 4294967295 characters.
-----
The *number* types are:
-----
TINYINT( ) -128 to 127 normal
0 to 255 UNSIGNED.
SMALLINT( ) -32768 to 32767 normal
0 to 65535 UNSIGNED.
MEDIUMINT( ) -8388608 to 8388607 normal
0 to 16777215 UNSIGNED.
INT( ) -2147483648 to 2147483647 normal
0 to 4294967295 UNSIGNED.
BIGINT( ) -9223372036854775808 to 9223372036854775807 normal
0 to 18446744073709551615 UNSIGNED.
FLOAT A small number with a floating decimal point.
DOUBLE( , ) A large number with a floating decimal point.
DECIMAL( , ) A DOUBLE stored as a string , allowing for a fixed decimal point.
-----
The *date* types are:
-----
DATE YYYY-MM-DD.
DATETIME YYYY-MM-DD HH:MM:SS.
TIMESTAMP YYYYMMDDHHMMSS.
TIME HH:MM:SS.
-----
The *misc* types are:
-----
ENUM ( ) Short for ENUMERATION which means that each column may have
one of a specified possible values.
SET Similar to ENUM except each column may have more than one of the
specified possible values.
-----
Mapping MySQL Datatypes Into Java
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
See
http://www.roseindia.net/jdbc/jdbc-mysql/mapping-mysql-data-types-in-java.shtml[http://www.roseindia.net/jdbc/jdbc-mysql/mapping-mysql-data-types-in-java.shtml].
-----
MySQL Type Java Type
CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC java.math.BigDecimal
DECIMAL java.math.BigDecimal
BIT boolean
TINYINT byte
SMALLINT short
INTEGER int
BIGINT long
REAL float
FLOAT double
DOUBLE double
BINARY byte []
VARBINARY byte []
LONGVARBINARY byte []
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Tiimestamp
-----
Create a Table with Columns with Specified Datatypes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is explained at:
-----
http://www.tutorialspoint.com/mysql/mysql-create-tables.htm
-----
A PostgreSQL statement of the form:
-----
CREATE TABLE "CAGES_Texas" (
"modified" varchar(50),
"verbatimModified" varchar(50),
"minimumDepthInMeters" decimal,
"OccurrenceRemarks" text
) WITH OIDS;
-----
translates into a MySQL statement of the form:
-----
CREATE TABLE CAGES Texas (
modified varchar(100),
verbatimModified varchar(100),
minimumDepthInMeters decimal,
OccurrenceRemarks text
);
-----
PostgreSQL vs. MySQL Data Types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
These are compared at:
-----
http://sidu.sourceforge.net/sidu/data-type-mapping.php
-----
Database File Backup and Manipulation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shrinking ibdata1
^^^^^^^^^^^^^^^^^
This is described at:
-----
http://stackoverflow.com/questions/3456159/how-to-shrink-purge-ibdata1-file-in-mysql
-----
If you want to reclaim the space from +ibdata1+ you have to delete the file
and recreate it. This is done via the following procedure:
* Dump all databases using +mysqldump+, e.g.
** +mysqldump -u root -ppasswd CAGES > cages_backup.sql+
* Drop all databases except the +mysql+ database, e.g.
** +drop database CAGES;+
* Stop mysql.
** +/etc/init.d/mysqld stop+
* Delete the files +ibdata1+ and +ib_log+.
* Start mysql.
** +/etc/init.d/mysqld start+
* Restore from the dump files.
** +mysql -u root -p+
** +create database CAGES;+
** +exit+
** +mysql -u root -ppasswd CAGES < cages2_backup.sql+
Optimizations
~~~~~~~~~~~~~
Optimizing MySQL for Large Databases
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
See
http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/[+http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/+]:
. Use the +my-huge.cnf+ configuration file if you have more than 2GB of RAM.
. Add the following to the configuration file:
-----
max_connections = 1000
query_cache_size = 128M
table_cache = 2048M
open_files_limit = 2000
-----
See
http://www.biblibre.com/en/blog/entry/mysql-default-config-and-very-large-koha-database[+http://www.biblibre.com/en/blog/entry/mysql-default-config-and-very-large-koha-database+]:
Errors
~~~~~~
Error Message +InnoDB: Could not open or create data files+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A remedy for this can be found at:
+http://forums.mysql.com/read.php?22,428579,428773#msg-428773+
which is detailed below:
* +mysqldump+ everything
* stop +mysqld+
* add +innodb_file_per_table+ to +my.cnf+
* deleted +ibdata1+
* start +mysqld+
* reload the data (as seen in the immediately previous section)
Checking Remote MySQL Database with Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From barataria we check the connection to gcoos1:
-----
import MySQLdb
db = MySQLdb.connect(host="gcoos1.tamu.edu",user="baum",passwd="password",db="CAGES")
cursor = db.cursor()
sql = "SELECT * FROM Texas_Bays"
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
print row[0],row[1]
....:
1 SABINE LAKE
2 GALVESTON BAY
3 MATAGORDA BAY
4 SAN ANTONIO BAY
5 ARANSAS BAY
6 CORPUS CHRISTI BAY
7 UPPER LAGUNA MADRE
8 LOWER LAGUNA MADRE
9 EAST MATAGORDA BAY
11 CEDAR LAKES
17 off Sabine Lake
18 off Galveston-Freeport
19 off Matagorda-San Antonio-Aransas
20 off Corpus Christi-Upper Laguna Madre
21 off upper Laguna Madre-lower Laguna Madre
-----
CAGES Database Modifications
----------------------------
. All spaces in table and variable names replaced with underscores.
. Variable name +Length (Units)+ changed to +Length_Units+.
. Use the +OPTIMIZE TABLE+ command.
CAGES Texas Tables
------------------
The tables in the Texas portion of the CAGES dataset are:
-----
Texas_Bays 15
Texas_CPUE 1,025,700
Texas_Hydrological 39,450
Texas_Lengths 1,283,332
Texas_Samples 39,450
Texas_Species 26
Texas_Stations 1,420
Texas_SubBays 39
Texas_Trawls 1,025,700
-----
and the columns in each are:
+Texas_Bays+
-----
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| Bay_Code | int(11) | YES | | NULL | |
| Bay_Location | varchar(255) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
-----
+Texas_CPUE+
-----
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| Bay_Code | int(11) | YES | | NULL | |
| Site_Number | int(11) | YES | | NULL | |
| YYYY | int(11) | YES | | NULL | |
| MM | int(11) | YES | | NULL | |
| DD | int(11) | YES | | NULL | |
| Species_Code | int(11) | YES | | NULL | |
| Scientific_Name | varchar(255) | YES | | NULL | |
| cpue | double | YES | | NULL | |
+-----------------+--------------+------+-----+---------+-------+
-----
+Texas_Hydrological+
-----
+-------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| Sample_Code | int(11) | YES | | NULL | |
| Salinity | double | YES | | NULL | |
| Temperature | double | YES | | NULL | |
| Depth | double | YES | | NULL | |
| Turbidity | double | YES | | NULL | |
| Tow_Time | double | YES | | NULL | |
+-------------+---------+------+-----+---------+-------+
-----
+Texas_Lengths+
-----
+--------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| Sample_Code | int(11) | YES | | NULL | |
| Species_Code | int(11) | YES | | NULL | |
| Length | int(11) | YES | | NULL | |
+--------------+---------+------+-----+---------+-------+
-----
+Texas_Samples+
-----
+--------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| Sample_Code | int(11) | YES | | NULL | |
| Station_Code | int(11) | YES | | NULL | |
| YYYY | int(11) | YES | | NULL | |
| MM | int(11) | YES | | NULL | |
| DD | int(11) | YES | | NULL | |
+--------------+---------+------+-----+---------+-------+
-----
+Texas_Species+
-----
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| Species_Code | int(11) | YES | | NULL | |
| Scientific_Name | varchar(255) | YES | | NULL | |
| Common_Name | varchar(255) | YES | | NULL | |
+-----------------+--------------+------+-----+---------+-------+
-----
+Texas_Stations+
-----
+--------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| Station_Code | int(11) | YES | | NULL | |
| Site_Number | int(11) | YES | | NULL | |
| Bay_Code | int(11) | YES | | NULL | |
| SubBay_Code | int(11) | YES | | NULL | |
| Latitude | double | YES | | NULL | |
| Longitude | double | YES | | NULL | |
+--------------+---------+------+-----+---------+-------+
-----
+Texas_SubBays+
-----
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| SubBay_Code | int(11) | YES | | NULL | |
| Bay_Code | int(11) | YES | | NULL | |
| SubBay_Location | varchar(255) | YES | | NULL | |
+-----------------+--------------+------+-----+---------+-------+
-----
+Texas_Trawls+
-----
+--------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| Sample_Code | int(11) | YES | | NULL | |
| Species_Code | int(11) | YES | | NULL | |
| Number | int(11) | YES | | NULL | |
+--------------+---------+------+-----+---------+-------+
-----
Method 1
--------
Creating Indexes for Table Columns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Painful experience having shown that it will take forever to perform the
upcoming +Step 1+ without creating them, we will now create indexes for
various table columns. The generic procedure is:
-----
CREATE INDEX index_name ON table_name(column_name)
-----
Starting with the +Texas_Bays+ table, we create the needed indexes via:
-----
CREATE INDEX Texas_Bays_Bay_Location ON Texas_Bays(Bay_Location);
CREATE INDEX Texas_Bays_Bay_Code ON Texas_Bays(Bay_Code);
-----
Now we do the same with the +Texas_Samples+ table:
-----
CREATE INDEX Texas_Samples_YYYY ON Texas_Samples(YYYY);
CREATE INDEX Texas_Samples_MM ON Texas_Samples(MM);
CREATE INDEX Texas_Samples_DD ON Texas_Samples(DD);
CREATE INDEX Texas_Samples_Station_Code ON Texas_Samples(Station_Code);
CREATE INDEX Texas_Samples_Sample_Code ON Texas_Samples(Sample_Code);
-----
And for +Texas_Species+:
-----
CREATE INDEX Texas_Species_Scientific_Name ON Texas_Species(Scientific_Name);
CREATE INDEX Texas_Species_Common_Name ON Texas_Species(Common_Name);
CREATE INDEX Texas_Species_Species_Code ON Texas_Species(Species_Code);
-----
And for +Texas_Stations+:
-----
CREATE INDEX Texas_Stations_SubBay_Code ON Texas_Stations(SubBay_Code);
CREATE INDEX Texas_Stations_Latitude ON Texas_Stations(Latitude);
CREATE INDEX Texas_Stations_Longitude ON Texas_Stations(Longitude);
CREATE INDEX Texas_Stations_Site_Number ON Texas_Stations(Site_Number);
CREATE INDEX Texas_Stations_Bay_Code ON Texas_Stations(Bay_Code);
CREATE INDEX Texas_Stations_Station_Code ON Texas_Stations(Station_Code);
-----
And for +Texas_Hydrological+:
-----
create index Texas_Hydrological_Sample_Code on Texas_Hydrological(Sample_Code);
create index Texas_Hydrological_Salinity on Texas_Hydrological(Salinity);
create index Texas_Hydrological_Temperature on Texas_Hydrological(Temperature);
create index Texas_Hydrological_Depth on Texas_Hydrological(Depth);
create index Texas_Hydrological_Turbidity on Texas_Hydrological(Turbidity);
create index Texas_Hydrological_Tow_Time on Texas_Hydrological(Tow_Time);
-----
-----
show index from Texas_Hydrological;
+--------------------+------------+--------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name |
Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed |
Null | Index_type | Comment | Index_comment |
+--------------------+------------+--------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Texas_Hydrological | 1 | Texas_Hydrological_Sample_Code |
1 | Sample_Code | A | 39777 | NULL | NULL | YES | BTREE
| | |
| Texas_Hydrological | 1 | Texas_Hydrological_Salinity |
1 | Salinity | A | 200 | NULL | NULL | YES | BTREE
| | |
| Texas_Hydrological | 1 | Texas_Hydrological_Temperature |
1 | Temperature | A | 200 | NULL | NULL | YES | BTREE
| | |
| Texas_Hydrological | 1 | Texas_Hydrological_Depth |
1 | Depth | A | 200 | NULL | NULL | YES | BTREE
| | |
| Texas_Hydrological | 1 | Texas_Hydrological_Turbidity |
1 | Turbidity | A | 200 | NULL | NULL | YES | BTREE
| | |
| Texas_Hydrological | 1 | Texas_Hydrological_Tow_Time |
1 | Tow_Time | A | 200 | NULL | NULL | YES | BTREE
| | |
+--------------------+------------+--------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
-----
And for +Texas_Trawls+:
-----
create index Texas_Trawls_Sample_Code on Texas_Trawls(Sample_Code);
create index Texas_Trawls_Species_Code on Texas_Trawls(Species_Code);
create index Texas_Trawls_Number on Texas_Trawls(Number);
-----
We didn't create indexes for all the columns of all the tables, basically
because this many was enough to bring the time for creation of our combined
table down under 10 minutes, as opposed to grinding on it for over 3 days
without finishing before we created the indexes.
Now on to a three step method for creating our final database.
Join Source Tables Into a Combined +CAGES_Texas_Join_Trawls_Lengths_Image+ Table
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a three step process.
Create the +CAGES_Texas_Join_Trawls_Lengths_Image+ Table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Create the table +CAGES_Texas_Join_Trawls_Lengths_Image+.
-----
CREATE TABLE
CAGES_Texas_Join_Trawls_Lengths_Image
SELECT
Texas_Trawls.Sample_Code,
Texas_Samples.Station_Code,
Texas_Stations.Site_Number,
Texas_Stations.Bay_Code,
Texas_Bays.Bay_Location,
Texas_Stations.SubBay_Code,
Texas_Stations.Latitude,
Texas_Stations.Longitude,
Texas_Samples.YYYY,
Texas_Samples.MM,
Texas_Samples.DD,
Texas_Trawls.Species_Code,
Texas_Species.Scientific_Name,
Texas_Species.Common_Name,
Texas_Trawls.Number,
NULL as Length,
Texas_Hydrological.Depth,
Texas_Hydrological.Tow_Time,
NULL as cpue
FROM
Texas_Trawls,
Texas_Hydrological,
Texas_Samples,
Texas_Species,
Texas_Stations,
Texas_Bays
WHERE
Texas_Trawls.Number=0
AND
Texas_Hydrological.Sample_Code=Texas_Trawls.Sample_Code
AND
Texas_Samples.Sample_Code=Texas_Trawls.Sample_Code
AND
Texas_Stations.Station_Code=Texas_Samples.Station_Code
AND
Texas_Species.Species_Code=Texas_Trawls.Species_Code
AND
Texas_Stations.Station_Code=Texas_Samples.Station_Code
AND
Texas_Bays.Bay_Code=Texas_Stations.Bay_Code;
-----
Create table +CAGES_Texas_Join_Trawls_Lengths_Image+
-----
CREATE TABLE CAGES_Texas_Join_Trawls_Lengths_Image (
Sample_Code int(11),
Station_Code int(11),
Site_Number int(11),
Bay_Code int(11),
Bay_Location varchar(50),
SubBay_Code int(11),
Latitude double,
Longitude double,
YYYY int(11),
MM int(11),
DD int(11),
Species_Code int(11),
Scientific_Name varchar(50),
Common_Name varchar(50),
Number int(11),
Length int(11),
Depth double,
Tow_Time double,
cpue double
);
-----
This tables looks like (via +describe
CAGES_Texas_Join_Trawls_Lengths_Image;+):
-----
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Sample_Code | int(11) | YES | | NULL | |
| Station_Code | int(11) | YES | | NULL | |
| Site_Number | int(11) | YES | | NULL | |
| Bay_Code | int(11) | YES | | NULL | |
| Bay_Location | varchar(50) | YES | | NULL | |
| SubBay_Code | int(11) | YES | | NULL | |
| Latitude | double | YES | | NULL | |
| Longitude | double | YES | | NULL | |
| YYYY | int(11) | YES | | NULL | |
| MM | int(11) | YES | | NULL | |
| DD | int(11) | YES | | NULL | |
| Species_Code | int(11) | YES | | NULL | |
| Scientific_Name | varchar(50) | YES | | NULL | |
| Common_Name | varchar(50) | YES | | NULL | |
| Number | int(11) | YES | | NULL | |
| Length | int(11) | YES | | NULL | |
| Depth | double | YES | | NULL | |
| Tow_Time | double | YES | | NULL | |
| cpue | double | YES | | NULL | |
+-----------------+-------------+------+-----+---------+-------+
-----
First +CAGES_Texas_Join_Trawls_Lengths_Image+ Insert
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
First insert step into +CAGES_Texas_Join_Trawls_Lengths_Image+.
-----
insert into
CAGES_Texas_Join_Trawls_Lengths_Image(Sample_Code,
Station_Code,
Site_Number,
Bay_Code,
Bay_Location,
SubBay_Code,
Latitude,
Longitude,
YYYY,
MM,
DD,
Species_Code,
Scientific_Name,
Common_Name,
Number,
Length,
Depth,
Tow_Time,
cpue)
select
Texas_Trawls.Sample_Code,
Texas_Samples.Station_Code,
Texas_Stations.Site_Number,
Texas_Stations.Bay_Code,
Texas_Bays.Bay_Location,
Texas_Stations.SubBay_Code,
Texas_Stations.Latitude,
Texas_Stations.Longitude,
Texas_Samples.YYYY,
Texas_Samples.MM,
Texas_Samples.DD,
Texas_Trawls.Species_Code,
Texas_Species.Scientific_Name,
Texas_Species.Common_Name,
Texas_Trawls.Number,
NULL as Length,
Texas_Hydrological.Depth,
Texas_Hydrological.Tow_Time,
NULL as cpue
FROM
Texas_Trawls,
Texas_Hydrological,
Texas_Samples,
Texas_Species,
Texas_Stations,
Texas_Bays
WHERE
Texas_Trawls.Number=0
AND
Texas_Hydrological.Sample_Code=Texas_Trawls.Sample_Code
AND
Texas_Samples.Sample_Code=Texas_Trawls.Sample_Code
AND