There is just too much out there for so many difference flavours. Just for the record, everything here work for FreeBSD-10, 11 and 12 running mysql56 at minumum and should be the closest for all of Linux. I believe Security has been well addressed. If not please let me know. For nowe it's one down and two to go.
First we must create a database and a table before moving on:
OK let's go:
weather_am.csv
Code:
March 01 2020,Sunday,6:00am,42 F,Clear and Sunny,Houston,TX,0001
Run it from the command line for testing:
Code:
# mysql -e "LOAD DATA INFILE '/var/db/mysql_secure/weather_am.csv' INTO TABLE weather_am FIELDS TERMINATED BY ','" \
-u root -p weather;
Enter password:
ERROR 1290 (HY000) at line 1: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
So the battle begin!
Inside mysql Do This:
Code:
root@localhost [mysql]> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| secure_file_priv | /var/db/mysql_secure/ |
+------------------+-----------------------+
.
Code:
# mv weather_am.csv /var/db/mysql_secure/weather_am.csv
Code:
# chmod 700 /var/db/mysql_secure/weather_am.csv
.
In our my.cnf write these:
Code:
[client]
password="pass39485"
[mysql]
local-infile=1
[mysqld]
local-infile=1
.
or
.
Then run from the command-line again:
Empty return means success!
Code:
# mysql -e "LOAD DATA INFILE '/var/db/mysql_secure/weather_am.csv' INTO TABLE weather_am FIELDS TERMINATED BY ','" \
-u root weather;
#
\quit
# ####################
# ####################
or execute it on command-line:
Code:
# ./weather.sh
#
\quit
See Result:
Code:
mysql -u root -p
Enter password:
root@localhost [(none)]> use mysql;
Database changed
root@localhost [mysql]> use weather;
Database changed
root@localhost [weather]> SELECT * FROM weather_am WHERE 1=1;
+---------------+--------+--------+------+-----------------+---------+-------+----+
| date | day | ttime | temp | view | City | state | id |
+---------------+--------+--------+------+-----------------+---------+-------+----+
| March 01 2020 | Sunday | 6:00am | 42 F | Clear and Sunny | Houston | TX | 12 |
+---------------+--------+--------+------+-----------------+---------+-------+----+
1 row in set (0.00 sec)
root@localhost [weather]>
To automate, I would use cron or whatever possible.
Well it's curtains for my original program. I really feel like @laserlight have made a real programmer out of me overnight. I never read so much in my life. Now it all seem so easy.
Also I realize stripping info the way I was doing it is not good. I seriously did not take into account that the owner of that page might change his format at any time.
Where are you getting your weather information from? If it's through an API for a weather service, …
.
.
.
Then you don't need to generate the CSV file. Have your program invoke the database API to insert the data directly to the database. Actually, if you don't need a historical record, then for mysql you should be using insert ... on duplicate key update instead.
I have not completely figured out what most of this mean. I searched the keywords but found only two links about API other then what is said in the MySQL docs.One talk about the API and certificates and the other was some kind of service or program. But I did not see none of that in the doc's. Maybe I missed something.
I’m guessing the way to do this would be to contact weather.com and apply for an subscription. Would that be where the API and certificates for database access comes in? Sound like common since but sometimes I think i’m missing some screws because I'm still not sure.
I'm beginning to feel like c++
How could I ever Thank you laserlight