Import and export CSV file into MySQL Table


Clean up csv for file like below

    "Email"
    "abc@exammle.com"
    "xyz@kdjfi.com.np"
    "oioi@uyii.net"
    ...  ## note not commas and carriage returns because csv was imported from windows os

move the files to /var/lib/mysql-files  directory 

sed -i  's/$/,/g'  Aggregate-SentList-Introduction.csv 

sed -i  's/\r//g'  Aggregate-SentList-Introduction.csv 

First of all create necessary table for example `table name = gel `

mysql> create table gel(email VARCHAR(255));

Now import the csv file 

mysql> LOAD DATA LOCAL INFILE '/home/user1/Desktop/temporary/gel.csv'
INTO TABLE store.gel
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

ignoring 1st row because it contained the column name for example

"Email List"
"jack@example.com"
"jill@abc.com"
"wfpk@unitki.com"
....
...

mysql> LOAD DATA LOCAL INFILE '/home/user1/Desktop/temporary/sentlog1.csv'  INTO TABLE store.sent1  FIELDS TERMINATED BY ','  ENCLOSED BY '"'
LINES TERMINATED BY '\n' IGNORE 1 ROWS;
Query OK, 3376 rows affected (0.66 sec)
Records: 3376  Deleted: 0  Skipped: 0  Warnings: 0

mysql> LOAD DATA LOCAL INFILE '/home/user1/Desktop/temporary/sentlog2.csv'  INTO TABLE store.sent2  FIELDS TERMINATED BY ','  ENCLOSED BY '"'
LINES TERMINATED BY '\n' IGNORE 1 ROWS;
Query OK, 8732 rows affected (1.71 sec)
Records: 8732  Deleted: 0  Skipped: 0  Warnings:


EXPORT sql select result

mysql> SELECT email FROM blocks WHERE email NOT IN (select mail from `TABLE 2`) INTO OUTFILE '/var/lib/mysql-files/filteredaug24.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

Query OK, 67782 rows affected (0.62 sec)
If file exist then it will give error you need to remove it first

Useful query
SELECT emails FROM sent
LEFT JOIN blocks ON sent.emails=blocks.email
WHERE blocks.email IS NULL;

OR

SELECT emails FROM sent
WHERE emails NOT IN ( select email from blocks )
INTO OUTFILE '/var/lib/mysql-files/filteredaug24-5.csv'  LINES TERMINATED BY '\n' ;

nginx micro caching

What we wanted to achieve in our test configuration was to have a URL like:
http://www.example.com/image/<width>x<height>/<URL>
...that would retrieve the image at:
https://upload.wikimedia.org/<URL>
...then resize it on the fly, cache it and serve it.
Our setup ended up being almost the same as the one in that blog post, with some slight differences.
Requirements installation

First, as the post points out, the Image Filter module is not installed by default on many Linux distributions. As we're using Nginx's official repositories, it was just a matter of installing the nginx_module_image_filter package and restarting the service.
Cache Storage configuration

Continuing following the post's great instructions, we set up the cache in our main http section, tuning each parameter to fit ur specific needs. We wanted a 10MB storage space for keys and 100MB for actual images, that will be removed after not being accessed for 40 days. The main configuration entry was then:

proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=nginx_cache:10M max_size=100M inactive=40d;

This went straight in the http section of nginx.conf.
Caching Proxy configuration

Next, we configured our front facing virtual host. In our case, we needed the reverse proxy to live within an already existing site, and that's why we chose the /image/ path prefix.

server {
      ...
 
      location /image/ {
          proxy_pass http://127.0.0.1:20000;
          proxy_cache nginx_cache;
          proxy_cache_key "$proxy_host$uri$is_args$args";
      }
 
      location / {
          # other locations we may need for the site.
          root /var/www/whatever;
      }
 
  }


Every URL starting with /image/ would be server from the cache if present, otherwise it would be proxied to our Resizing Server, and cached for 30 days, as desired.
Resizing Server configuration

We then configured the resizing server, using a regexp to extract the width, height and URL of the image we desire.
The server will proxy the request to https://upload.wikimedia.org/ looking for the image, resize it and then serve it back to the Caching Proxy. We preferred to keep it simple and tidy, as we didn't actually need any aws-related configuration as the blog post did.


Note that we may also use image_filter resize and crop options, should we need different results than just resizing.
Testing the final result

You should now be able to fire up your browser and access an URL like:

http://www.example.com/image/150x150/wikipedia/commons/0/01/Tiger.25.jpg



...and enjoy your caching, resizing, reverse proxying image server.
Optionally securing access to your image server

As this was not a public server, we didn't use any security mechanism to validate the request.
The original blog post, though, reports a very simple and clever way to prevent abuse from unauthorized access, using the Secure Link module.
To access your server you will now need to add an auth parameter to the request, with a secure token that can be easily calculated as an MD5 hash.
This is the simple Bash command we used to test it:
1
echo -n '/image/150x150/wikipedia/commons/0/01/Tiger.25.jpg your_secret' | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =


.and the resulting URL would be:
http://www.example.com/image/150x150/wikipedia/commons/0/01/Tiger.25.jpg?auth=TwcXg954Rhkjt1RK8IO4jA

http://blog.endpoint.com/2016/05/caching-resizing-reverse-proxying-image-server-nginx.html

jenkins reset password

edit /var/lib/jenkins/users/username/config.xml

<password> replace below string </password>

#jbcrypt:$2a$10$razd3L1aXndFfBNHO95aj.IVrFydsxkcQCcLmujmFQzll3hcUrY7S

password= test

Delete common rows between tables


tableA                                                        
apple@gmail.com
ram@gmail.com
user@hotmail.com
jai@qqmail.com
bai@example.com

tableB
ram@gmail.com
jai@qqmail.com

Query

delete
    from tableA
where exists
  ( select 1 
         from tableB
          where email = tableA.email )

Resulting table tableA  where common item from tableB is deleted: 

TableA
apple@gmail.com
user@hotmail.com
bai@example.com

part 5 dockerizing simple flask application and docker exec

### vim Dockerfile

FROM python:3.5
RUN pip install  Flask==0.11.1
RUN useradd -ms /bin/bash admin
USER admin
WORKDIR /app
COPY app /app
CMD ["python", "app.py"]

###

docker build -t urgen/dockerapp:1.01

docker images   <copy imageid>

docker run -d -p 5000:8080

    -d = run container in background
    -p = expose port
    5000 = port of container
    8080 = port of real host


user1@localhost ~ $ docker run -d -i -t busybox
8ba73738bf52630e31106be2f3a1cb4d4e0ab8f79d311f38c6ec8ff5ce7eba24

# to docker exec the container must be running in background (-d option)
docker exec -it 8ba73738bf52630e31106be2f3a1cb4d4e0ab8f79d311f38c6ec8ff5ce7eba24  sh

part 4 push docker image to docker hub public

1) docker images  ## list images

docker tag  <image id>  <docker hub repositoryname>:<tag>

2) docker tag  c75bebcdd211 urgensherpa2/box1:1.01

docker login --username=urgensherpa2
password:
Login succeed

3) docker push urgensherpa2/box1:1.01

part 4 docker automate building images

Build docker images

   docker file - is text doc that contains all the instructions to assemble the image

By default the filename is "Dockerfile" where we put all the instructions

cd /home/user1/

# vim Dockerfile
FROM debian:jessie
RUN apt-get update
RUN apt-get install -y git vim rsync
COPY localfile.txt  /src/localfile.txt   ##copy local file to containers /src/ directory ..look ADD command too!

docker build -t repositoryname:tag .


docker build -t vieux/apache:2.0 .

docker build -t urgen/dockerfiledemo -f Dockerfile /home/user1/

docker build -t urgen/dockerfiledemo -f customdockerfilemame /home/user1/

OR

docker build -t ubuntu:latest .

    --tag, -t  = Name and optionally a tag in the ‘name:tag’ format
    --file, -f = Name of the Dockerfile (Default is ‘PATH/Dockerfile’)


in screenshot "Dockerfile" is saved at /home/user1/docker directory

part 3 docker build images and commit , delete and stop running containers

Docker image is made up of list of readonly layes that represent filesystem differences. image layers are stacked on top of each other to form up a base for container's filesystem

Install GIT in a base image called ubuntu:latest

# docker run -it ubuntu:latest
apt-get update && apt-get install -y git

exit

# docker ps -a     ...grab container id


Docker commit - Create a new image from a container's changes
## commit changes and save to a new container named ubuntu:1.00
docker commit 4188d246e83c urg3n/ubuntu:1.00

docker commit d823hjhd8fj2    repositoryname:tag

# list new images created
--> docker images

docker run -it urg3n/ubuntu:1.00

## Delete container !!! ##

docker ps -a   and grab container id

docker rm 247e45581fed    ### removes container with ID 247e45581fed

part 2 docker port mapping and run in background

## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100

## specify name for docker container we want to run
docker run  --name  mycontainer100 busybox:1.24
docker run  --name  mycontainer200 busybox:latest
docker ps -a

docker inspect containerid
##outpus image id , logpath,mac id

user1@localhost$ docker run -d busybox:latest sleep 10
a7393fc5cc8e1db7e87b9eb24151147

user1@localhost$ docker inspect a7393fc5cc8e1db7e87b9eb24151147


### docker tomcat
expose container port 8080 to host port 8888

docker run -it -p 8888:8080 tomcat:8.0

-->open browser--goto--> localhost:8888  it willopen tomcat server


# run container in detached mode

docker run -it -d -p 8888:8080 tomcat:8.0 

docker exec <name> /bin/cat /etc/profile
docker logs <name>

#docker run -d -p <hostport>:<containerPort>  nginx:latest

a7393fc5cc8e1db7e87b9eb24151147sf
docker logs a7393fc5cc8e1db7e87b9eb24151147sf

# Docker attach or login into the running container :-

docker exec -it containeridORname /bin/bash

# Docker management
# delete all containers
docker ps -aq | xargs docker rm -f

docker logs <cont id>   # view the output logs of container






mysql database size

To determine the sizes of all of your databases, at the mysql> prompt type the following command:

SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;


To determine the sizes of all of the tables in a specific database, at the mysql> prompt, type the following command. Replace database_name with the name of the database that you want to check:

SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;