The initial access in Millimeter wave (mmWave) 5G communications is very challenging and time consuming. In general, mmWave and terahertz communications require the use of directional antennas to seek narrow beams. However, due to this directionality, many issues can impact the beam alignment between transmitter and receiver. In this paper, we present a comprehensive survey of beam alignment and initial access in mmWave and terahertz 5G/6G systems. First, we present a detailed overview of initial access methods, techniques, and beam management procedures. Then, we classify recent works related to beam alignment based on their objective functions (i.e., latency, power allocation, QoS, energy consumption, cost). We also highlight the beam alignment in terahertz 6G, where we find that deep learning and reconfigurable intelligent surface are the two protagonists that help to achieve fast beam alignment.INDEX TERMS 5G/6G, mmWave, terahertz, beamforming, initial access, beam alignment, beam steering, reconfigurable intelligent surface.