當前位置:首頁 » 雲伺服器 » mysql怎麼連接伺服器

mysql怎麼連接伺服器

發布時間: 2022-01-12 23:54:50

A. mysql是怎麼連接資料庫伺服器

1)連接Oracle 8/8i/9i/10g/11g(thin模式)

Class.forName("oracle.JDBC.driver.OracleDriver").newInstance();
String url="JDBC:oracle:thin:@localhost:1521:orcl" //orcl為Oracle資料庫的SID
String user="test";
String password="test";
Connection con=DriverManager.getConnection(url,user,password);
2)連接DB2資料庫
Class.forName("com.ibm.db2.jcc.DB2Driver");
String url="JDBC:db2://localhost:5000/testDb";/**資料庫連接串**/
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
3)連接MySQL資料庫
Class.forName("com.mysql.jdbc.Driver");
String url="JDBC:mysql://localhost:8080/testDB";
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
4)連接SQL Server資料庫
Class.forName("com.microsoft.JDBC.sqlserver.SQLServerDriver");
String url="JDBC:microsoft:sqlserver://localhost:1433;DatabaseName=testDb";
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
5)連接PostgreSQL資料庫
Class.forName("org.postgresql.Driver");
String url="JDBC:postgresql://localhost/testDb";
String user="test"; String password="test";
Connection con=DriverManager.getConnection(url,user,password);
6)連接Access資料庫
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="JDBC:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/testDb/mdb");
Connection conn=DriverManager.getConnection(url,"","");
7連接Sybase資料庫
Class.forName("com.sybase.JDBC.SybDriver");
String url="JDBC:sybase:Tds:localhost:5007/testDb";
Properties pro=System.getProperties();
pro.put("user","userId");
pro.put("password","user_password");
Connection con=DriverManager.getConnection(url,pro);
8連接informix資料庫
Class.forName("com.informix.JDBC.ifxDriver");
String url="JDBC:informix-sqli:localhost:1533/testDb:INFORMIXSERVER=myserver"user=testUser;password=testpassword"; Connection con=DriverManager.getConnection(url);

示例:
連接SQL Server2008R2資料庫
首先Build Path → 添加外部sqljdbc.jar驅動

import java.sql.*;
public class DB {
public static void main(String[] args) throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName=資料庫名", "sa", "1234");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from 表名");
while(rs.next()) {
System.out.println("id為:" + rs.getString("id") + "name為:" + rs.getString("name"));
}
System.out.println("資料庫連接成功!");
rs.close();
stmt.close();
conn.close();
System.out.println("資料庫成功關閉!");
}
}

B. 如何連接mysql資料庫伺服器

1,打開Navicat for MySQL,點擊左上角「鏈接」按鈕,如下圖:

2,在彈出的新建鏈接對話框中,填寫遠程資料庫伺服器IP地址,賬號,密碼等信息。如下圖:

3,最後確定保存即可。
本回答由電腦網路分類達人 李孝忠推薦
評論(1)
5 2

zengchao623
採納率:52% 來自團隊:電腦網路行家 擅長: 互聯網 編程語言 操作系統/系統故障 JavaScript Html/Css
其他回答

文件--》創建連接,輸入相關信息確定就可以啦

C. 如何連接到伺服器上的mysql資料庫

首先你要先和伺服器的網路是能Ping通的
MYSQL連接一般需要輸入目標伺服器的IP地址,埠號,用戶名和密碼。
如:ip地址:192.168.11.101
埠 :3306
用戶名:root
密碼:root
其中用戶名和密碼一般輸入root都是可以進入的。不行就去目標伺服器上的資料庫管理下用戶。
MYSQL一般都是用NAVITE for mysql。點擊左上角的連接按鈕。輸入以上信息就可以了,記得先PING網路。

D. mysql如何遠程連接伺服器

Mysql提供了一套C API函數,可以直接操縱資料庫(功能還是很強大的). 用VC開發一個客戶端程序,需要連接一個遠程的資料庫.

第一步:建立一個MYSQL"對象 ",然後對其初始化(文檔中要求的);

第二步:使用mysql_real_connect函數連接,不建議使用mysql_connect (這是一個較早的版本);

注意:通過TCP/IP方式連接,所以HOST一項填伺服器的IP地址,例如: 166.111.***.***

其次,提供登陸名(USER)和密碼(PWD),以及默認連接的資料庫名稱.

當Mysql建構在一台linux伺服器上,自然存在linux本身的密碼校驗.

我不知道有什麼好的方法,只是試著將資料庫的username和pwd設置的和linux的一致,然後求通過了

E. mysql資料庫怎麼連接伺服器

mysql
-u用戶名
-h
主機名

-p
前提是伺服器的mysql上有該用戶,以及對應的IP
可登入mysql伺服器上執行
grant
all
on
test.*
to
用戶名@『
客戶機
IP』
identified

by
'密碼'

flush
privileges;
#刷新許可權表,讓所做修改生效
上面指令的意思是
將test這個資料庫的全部內容以及全部的操作許可權
賦權
給從特定IP上登入到本伺服器的用戶。

F. 請教下mysql怎麼連接伺服器

G. 怎麼連接到伺服器上的mysql資料庫

mysql -u用戶名 -h主機名 -p

前提是伺服器的mysql上有該用戶,以及對應的IP
可登入mysql伺服器上執行
grant all on test.* to 用戶名@『客戶機IP』 identified by '密碼' ;
flush privileges; #刷新許可權表,讓所做修改生效

上面指令的意思是 將test這個資料庫的全部內容以及全部的操作許可權賦權給從特定IP上登入到本伺服器的用戶。

H. win7中怎麼連接MySQL伺服器

你先運行 CMD
然後 進入到那個 mysql 的目錄下, 再運行。
例如:

D:\>cd mys*

D:\mysql-5.1.50-win32>cd bin

D:\mysql-5.1.50-win32\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.50-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Database changed

熱點內容
筆記本什麼配置能流暢運行cf 發布:2024-09-20 00:14:19 瀏覽:951
實測華為編譯器 發布:2024-09-19 23:50:52 瀏覽:821
linux匯總 發布:2024-09-19 23:46:39 瀏覽:452
阿里雲伺服器環境搭建教程 發布:2024-09-19 23:21:58 瀏覽:837
黃色文件夾圖標 發布:2024-09-19 23:19:22 瀏覽:684
mysql資料庫導出導入 發布:2024-09-19 23:00:47 瀏覽:183
lua腳本精靈 發布:2024-09-19 23:00:41 瀏覽:659
任務欄文件夾圖標 發布:2024-09-19 22:54:25 瀏覽:101
解壓來一波 發布:2024-09-19 22:46:36 瀏覽:933
mysqlpythonubuntu 發布:2024-09-19 22:46:27 瀏覽:501