Stochastic optimal control based on reliability plays a crucial role in mitigating structural failure and ensuring safe operation. For general stochastic vibration systems, a data-driven method for reliability-based optimal control is proposed based on random state data. Firstly, the feedback control is split into conservative and dissipative components in coherence with physical intuition, and each component is expanded upon using pre-selected basic functions, resulting in a modified system with undetermined coefficients. Then, from discrete random samples, the expressions for the probability densities of the first-passage time and the stationary response can be identified, explicitly including system and excitation parameters, as well as initial and safety boundary conditions. Finally, a performance index, combining system reliability and control cost, is constructed and can be explicitly expressed in terms of the undetermined coefficients of the control forces. The optimal control problem for determining the optimal control forces is reformulated as an optimization problem for determining the coefficients that minimize the performance index. This unconstrained optimization problem can be easily solved. Three typical nonlinear stochastic systems, a controlled Duffing oscillator, a controlled nonlinear hysteretic system, and a controlled 2-DOF nonlinear dynamical system, are given to illustrate the validity and accuracy of the proposed data-driven method. Additionally, the control performance of the optimal control strategy in improving the system reliability is also discussed.