At what times were people interested in prime numbers While prime numbers are central objects in mathematics it looks that they were ignored and forgotten for long periods of time. I am interested to get some facts and insights about this matter, in particular:
1) Were prime numbers studied in ancient times only by the ancient Greeks? At what periods were they studied by the ancient Greeks themselves?
2) Is it the case that people largely or even entirely lost their interest in the prime numbers for about fifteen centuries until Fermat? What are the facts of the matter and what are the  reasons that may explain these facts.
(motivated by conversations with Ron Livne.)
 A: For 2), it depends a little on how you interpret the question.  Primes in the abstract are covered in Chapter XVIII of Dickson's History of the Theory of Numbers, vol I.  There's not much between Euclid and Euler.  
On the other hand, primes of special forms related to perfect numbers or amicable pairs were written about extensively in the 15 centuries before Fermat.  Admittedly, often incorrectly or with little content.  In Chapter I of Dickson, Carolus Bovillus (1470-1553) claims that $2^n-1$ is prime if $n$ is odd, giving the example $511=2^9-1$.  (In fact $7|511$).  But it was not all nonsense.  For example, Thabit ibn Qurra (836-901) showed that if
$$
p=3\cdot 2^{k-1}-1, q=3\cdot 2^k-1, r=9\cdot 2^{2k-1}-1
$$
are all primes, then
$$
m=p\cdot q\cdot 2^k, n=r\cdot 2^k
$$
form an amicable pair: $s(m)=n$ and $s(n)=m$, where $s(k)$ is the sum of the proper divisors of $k$.
A: In recent times it has been claimed that Bhaskara I (around 700) and
more definitely Ibn al-Haytham (965 - 1040) were aware of Wilson's
theorem. This is much earlier than Wilson's theorem was previously
supposed to be known, so perhaps there is more to be discovered
about early work on prime numbers.
A: Gil Kalai writes:

2) Is it the case that people largely or even entirely lost their interest in the prime 
  numbers for about fifteen centuries until Fermat? What are the facts of the matter and what 
  are the reasons that may explain these facts.

It depends on who the people here are! 
(a) In the Arabic-speaking world, where mathematics was alive and well, prime numbers did not lose their interest; in fact, as John Stillwell said above, the statement "Wilson's theorem" dates from that period.
(b) In most of Europe, there was essentially no pure mathematics of interest throughout the Middle Ages. (About the one exception is Fibonacci, who of course got at least part of his mathematical education outside Europe.)
Still, it would not surprise me if prime numbers turned out to be one of the few things in what we call number theory that was ever discussed in Western Europe during the Middle Ages. Reason: the popularity of Nicomachus's Arithmetic, translated (freely) by Boethius. 

Boethius' Latin version was destined to exert a great influence on subsequent 
  encyclopedic authors of the sixth and seventh centuries and throughout the Middle Ages up 
  to the sixteenth century. From the sixth to the twelth century, when Greek geometry had 
  almost vanished and science was at its lowest ebb, Boethius's Arithmetic, for all its 
  faults, preserved the ideal of a theoretical science. Not until the thirteenth century, 
  when Jordanus de Nemore's Arithmetic appeared in ten books, do we have a theoretical 
  arithmetic on the Euclidean model, complete with proofs.

E. Grant,  A source book in medieval science, Harvard U Press, 1974.
From a quick look at Nicomachus's original, it seems to be almost entirely about properties of integers, which are sometimes given a mystical or moral significance. Primality appears as one noteworthy property among several, side by side with being odd, even, triangular, pentagonal, heptagonal, perfect, superparticular, heteromecic, etc.
(Nothing or almost nothing non-trivial seems to be shown about any of these.)
As for Diophantus's Arithmetic, (a) it could not have an influence in Western Europe during the Middle Ages, as it was unknown there, (b) at any rate, it is largely about what we now would call the (highly ingenious!) construction of rational maps from n-dimensional affine space to varieties. There's very little in Diophantus about integers, and that as auxiliary material. Hence the fact that he does not really discuss prime numbers as such does not tell us much.
A: According to the book of David Wells on prime numbers (see page 43), critics think that Diophantus (b. between A.D. 200 and 214, d. between 284 and 298 at age 84) knew (empirically, presumably) that every prime of the form $4n+1$ is a sum of two squares. 
A: This is a VERY interesting question to which I do not have an answer, despite some research and much cogitation.  In India and China there was substantial deep mathematical thought well before 500 BCE. I find it hard to believe that people did not think about prime numbers but I have been able to find NO evidence.
It is striking to me that the earliest classical Greek mathematicians lived on the Greek shores of Turkey, not in mainland Greece. Some are said to have visited Egypt and inland Turkey, but the history is so vague as to be probably only conjectures made centuries after these people died.  There is little evidence that previous civilizations within the Greek area of travel, made substantial contributions to the kind of mathematical ideas that Greek mathematicians began to explore.  But why did  Thales of Miletus (ca. 624–548 BCE)  and Pythagoras of Samos (ca. 580–500 BCE) (he moved to Croton later) grow up where they did?
A: The Liber Abaci (1202) of Fibonacci contains a chapter on perfect numbers and Mersenne primes (of course Mersenne came much later, but possibly slightly before Fermat; he is born slightly before Fermat but is essentially a contemporary). 
I do not know if there are any new results; but at least it seems he was interested in them.
I am not sure if this counts as interested in prime numbers, but it is certainly number theory and involves primes very directly: the Chinses Remainder Theorem developped from about 3rd to 13th century in China (no surprise here); but also in 6th and 7th century in India.
A non-example would be the Chinese Hypothesis that used to be believed to originate in ancient China but did not. 
A: In response to question (1), an authoritative source is Peter Rudman in "How Mathematics Happened: The First 50,000 Years". Some revelant quotes:
On the Ishango bone (20,000 BCE):

The concept of division, which must
  precede the concept of prime number,
  probably did not evolve until after
  10,000 BCE and the emergence of
  herder-farmer cultures. The concept of
  prime numbers was probably only really
  understood after about 500 BCE by
  Greek mathematicians.

On the Babylonian clay tablet Plimpton 322 (1800 BCE):

This clay table shows that Babylonian
  scribes understood Pythagorean triples
  and perhaps the Pythagorean theorem.
  It also hints at some understandig of
  number concepts: prime numbers,
  composite numbers, regular numbers,
  rational numbers, and reduced
  fractions.

On the Sieve of Eratosthenes (250 BCE):

Is easy to apply and to understand.
  Babylonian scribes could have invented
  it more than one thousand years
  earlier --- but they apparently did
  not. Its invention was only possible
  after Pythagoras (500 BCE) and Euclid (300 BCE) had made the study of
  properties of numbers a subject worthy
  of the attention of Greek
  philosophers.

In response to question number 2, as described by O'Connor & Robertson, see also the Wikipedia entry,
Islamic mathematicians were the heirs of the Greeks throughout the Middle Ages, motivated in part by their interest in practical applications of geometry and number theory to architecture and decoration. (Similarly, the Islamic law of inheritance served as a drive for the development of algebra.) 
The translation by Islamic scholars of the mathematical works of Greek mathematicians was the principal route of transmission of these texts to the Middle Ages. For example, Diophantus's main work, the Arithmetica, was translated into Arabic by Qusta ibn Luqa (820–912), while the Latin translation had to wait until Xylander (1575).
Some notable Islamic heroes of prime numbers:
As noted by Stopple, the 9th century astronomer Thabit ibn Qurra studied prime numbers of the form $3\cdot 2^n-1$ (now called Thabit numbers).
Ibn Al-Haytham (born 965) seems to have been the first to attempt to classify all even perfect numbers (numbers equal to the sum of their proper divisors) as those of the form $2^{k-1}(2^k - 1)$ where $2^k - 1$ is prime. As noted by John Stillwell, Al-Haytham is also the first person that we know to state the theorem that if $p$ is prime then $1+(p-1)!$ is divisible by $p$ (only proven 750 years later by Lagrange).
Al-Farisi (born 1260) stated and attempted to prove the fundamental theorem of arithmetic, on the unique factorization of an integer into prime numbers.
Finally, the "why" question: There are no comparable heroes in Mediaeval Europe. My surmise is that this is because Christianity, with its figurative art, did not stimulate the interest in geometric and numerical patterns to the same extent as Islam did.
A: Bhaskaracharya in his Lilavati ( a compendium of math puzzles for his daugther) has several examples that include prime numbers
