In the spectrum sharing system (SSS) coexisting with multiple primary networks, a well-designed reconfigurable intelligent surface (RIS) is employed to control the radio environments of wireless channels and relieve the scarcity of the spectrum resource in this work, which can realize high spectral efficiency (SE) and energy efficiency (EE). Specifically, the SE enhancement in the considered SSS is decomposed into two subproblems which are a second-order programming (SOP) and a fractional programming of the convex quadratic form (CQFP), respectively, to optimize alternatively the beamforming vector at the secondary access point and the reflecting coefficients at the RIS. The CQFP subproblem about optimizing the reflecting coefficients can be solved by the domain and envelope shrinking algorithm (DES), providing the best SE performance. Besides, a low-complexity method of gradient-based linearization with domain (GLD) is proposed for obtaining a sub-optimal reflecting coefficients for fast deployment. Considering the power consumption in the practical application of RIS-aided SSS, the EE performance of our proposed GLD method has significant gain over that of the SSS without RIS. The simulation results indicate the effectiveness of the DES algorithm and show that the GLD method improves the SE and EE performance in RIS-aided SSS with multiple primary networks.