)到项目中。在Java代码中使用以下方式建立连接:,,
`java,import java.sql.Connection;,import java.sql.DriverManager;,,public class Main {, public static void main(String[] args) {, String url = "jdbc:mysql://localhost:3306/yourDatabase";, String user = "yourUsername";, String password = "yourPassword";, , try {, Class.forName("com.mysql.cj.jdbc.Driver");, Connection connection = DriverManager.getConnection(url, user, password);, System.out.println("连接成功!");, } catch (Exception e) {, e.printStackTrace();, }, },},
``mysql-connector-python
库:,,``bash,pip install mysql-connector-python,
`,,使用以下代码连接到数据库:,,
`python,import mysql.connector,,config = {, 'user': 'your_username',, 'password': 'your_password',, 'host': 'localhost',, 'database': 'your_database',},,connection = mysql.connector.connect(**config),cursor = connection.cursor(),
``mysql -h hostname -P port -u username -p
,-h指定主机名,
-P指定端口号,
-u指定用户名,
-p`用于输入密码。mysql-connector-java
依赖。Powered By Z-BlogPHP 1.7.3