This paper investigates a new scenario of spectrum sharing between unmanned aerial vehicle (UAV) and terrestrial wireless communication, in which a cognitive/secondary UAV transmitter communicates with a ground secondary receiver (SR), in the presence of a number of primary terrestrial communication links that operate over the same frequency band. We exploit the UAV's mobility in three-dimensional (3D) space to improve its cognitive communication performance while controlling the co-channel interference at the primary receivers (PRs), such that the received interference power at each PR is below a prescribed threshold termed as interference temperature (IT). First, we consider the quasi-stationary UAV scenario, where the UAV is placed at a static location during each communication period of interest. In this case, we jointly optimize the UAV's 3D placement and power control to maximize the SR's achievable rate, subject to the UAV's altitude and transmit power constraints, as well as a set of IT constraints at the PRs to protect their communications. Next, we consider the mobile UAV scenario, in which the UAV is dispatched to fly from an initial location to a final location within a given task period. We propose an efficient algorithm to maximize the SR's average achievable rate over this period by jointly optimizing the UAV's 3D trajectory and power control, subject to the additional constraints on UAV's maximum flying speed and initial/final locations. Finally, numerical results are provided to evaluate the performance of the proposed designs for different scenarios, as compared to various benchmark schemes. It is shown that in the quasi-stationary scenario the UAV should be placed at its minimum altitude while in the mobile scenario the UAV should adjust its altitude along with horizontal trajectory, so as to maximize the SR's achievable rate in both scenarios.the United States only in 2020. With the explosively increasing number of UAVs, how to integrate them into future wireless networks to enable their bidirectional communications with the ground users/pilots has become a critical task to be tackled. On one hand, for emergency situations (e.g., after natural disaster) and temporary hotspots (e.g., stadium during a football match), UAVs can be employed as aerial wireless communication platforms (e.g., relays or base stations (BSs)) to provide data access, enhance coverage, and improve communication rates for ground users [4], [5]. On the other hand, for UAVs in various missions (e.g., cargo delivery), it is crucial to enable them as aerial mobile users to access existing wireless networks (e.g., cellular networks), in order to support not only secure, reliable, and low-latency remote command and control, but also high-capacity mission-related data transmission [6]- [8]. Therefore, UAV-assisted terrestrial communications [4] and network-connected UAV communications [7] have become two widely investigated paradigms for integrating UAVs into future wireless communication networks.UAV communications are different...