本文目錄一覽:
- 1、使用mysql 一個資料庫中有倆個表: student(學生表) 和score(成績表)
- 2、Java中怎樣在MyEclipse的console控制台上顯示mysql資料庫表的內容
- 3、怎樣在MySQL資料庫中導出整個資料庫
- 4、編寫java程序實現把MySQL資料庫中的student表中數據進行列印輸出?
- 5、php 怎麼讀取mysql一條數據並輸出某一欄位
- 6、qt怎麼表格輸出mysql數據
使用mysql 一個資料庫中有倆個表: student(學生表) 和score(成績表)
SET @i=0。
SQL本身有數據導入的操作。但如果要從一個備份的文件中導入數據,則要進行另外的操作。下面以一個例子進行說明。
SQL伺服器上已有一個DOE資料庫,並且裡面有大量的數據,現準備從另外一個備份文件A1.BAK(不是DOE資料庫的備份文件)中導入另外的數據(即導入後在DOE中增加一些數據表,表中已錄有數據),並保持原DOE的數據不變。
擴展資料:
在為MySQL分配足夠的內存之前,請考慮不同領域對MySQL的內存需求。要考慮的關鍵領域是:並發連接——對於大量並發連接,排序和臨時表將需要大量內存。在撰寫本文時,對於處理3000+並發連接的資料庫,16GB到32GB的RAM是足夠的。
內存碎片可以消耗大約10%或更多的內存。像innodb_buffer_pool_size、key_buffer_size、query_cache_size等緩存和緩衝區要消耗大約80%的已分配內存。
參考資料來源:百度百科-MySQL資料庫
Java中怎樣在MyEclipse的console控制台上顯示mysql資料庫表的內容
顯示mysql資料庫表的內容需要把資料庫中取到的sql內容用system.out.print。
以下是例子:
package test;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
/*使用JDBC連接資料庫MySQL的過程
* DataBase:hj
* table:student
* */
public class Databasetest {
private static int count;
public static Connection getConnection() throws SQLException,
java.lang.ClassNotFoundException
{
//(1)載入MySQL的JDBC的驅動 Class.forName(“com.mysql.jdbc.Driver”);
//取得連接的url,能訪問MySQL資料庫的用戶名,密碼,資料庫名
String url = “jdbc:mysql://127.0.0.1:3306/”+”hj?useUnicode=truecharacterEncoding=utf8”;
String username = “root”;
String password =””;
//(2)創建與MySQL資料庫的連接類的實例
Connection con = (Connection) DriverManager.getConnection(url, username, password);
return con;
}
public static void main(String args[]) {
try
{
//(3)獲取連接實例con,用con創建Statement對象實例 sql_statement
Connection con = getConnection();
Statement sql_statement = (Statement) con.createStatement();
//插入語句
String sql = “insert into student(id,name,score)values(null,’梵蒂岡的發’,99)”;
count=sql_statement.executeUpdate(sql);
//(4)執行查詢,用ResultSet類的對象,返回查詢結果
String query = “select * from student”;
ResultSet result = sql_statement.executeQuery(query);
System.out.println(“student表數據如下:”);
System.out.println(“————————“);
System.out.println(“學號” + ” ” + “姓名” + ” ” + “成績”);
System.out.println(“————————“);
//對獲得的查詢結果進行處理,對Result類的對象進行操作
while (result.next())
{
int number=result.getInt(“id”);
String name=result.getString(“name”);
String score=result.getString(“score”);
//取得資料庫中的數據 System.out.println(“學號: ” + number + ” 姓名: ” + name + ” 成績: ” + score);
}
//關閉連接和聲明 sql_statement.close();
con.close();
} catch(java.lang.ClassNotFoundException e) {
//載入JDBC錯誤,所要用的驅動沒有找到
System.err.print(“ClassNotFoundException”);
//其他錯誤
System.err.println(e.getMessage());
} catch (SQLException ex) {
//顯示資料庫連接錯誤或查詢錯誤
System.err.println(“SQLException: ” + ex.getMessage());
}
}
}
運行結果:
student表數據如下:
————————
學號 姓名 成績
001 張三 90
怎樣在MySQL資料庫中導出整個資料庫
1、打開命令行,在命令行里輸入mysql,然後按回車就可以打開mysql的命令了。要注意的是區分大小寫,不能輸入Mysql。
2、進入命令後,可以使用use命令來轉到我們要查看的資料庫。
3、切換了資料庫後,我們就可以查看這個資料庫的表數據了。通過select語句就可以查詢表數據了,但要注意的是每條語句要以分號結束,否則就當語句還沒結束。會等待輸入。
4、以分號結束語句後,按回車鍵就能得到從MySQL資料庫中導出整個資料庫了。
編寫java程序實現把MySQL資料庫中的student表中數據進行列印輸出?
首先導入 mysql-connector-java-5.1.45-bin.jar 包7a686964616f31333365633936
代碼如下:
import java.io.*;import java.sql.*; public class App { public static void main(String[] args) { try { Class.forName(“com.mysql.jdbc.Driver”); // 資料庫用戶 String user = “root”; // 資料庫密碼 String password = “”; Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/db_sale”, user, password); Statement stmt = conn.createStatement(); // 查詢 , 從資料庫 db_sale 的 product 表中查詢 id, name, qty 欄位 ResultSet rs = stmt.executeQuery(“SELECT id, name, qty FROM product”); // 創建輸出文件 result.txt File file = new File(“d://result.txt”); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file)); while (rs.next()) { writer.write(String.valueOf(rs.getLong(1)) + “\t”); writer.write(rs.getString(2) + “\t”); writer.write(String.valueOf(rs.getInt(3))); writer.write(“\r\n”); //System.out.println(rs.getLong(1)); //System.out.println(rs.getString(2)); //System.out.println(rs.getLong(3)); } writer.flush(); writer.close(); rs.close(); stmt.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } }}
php 怎麼讀取mysql一條數據並輸出某一欄位
可以參考下面的代碼:
//連接資料庫伺服器
$link = mysql_connect(『host(伺服器ip地址,本地用localhost)』,’資料庫賬戶’,『資料庫密碼』);
//選擇要連接的資料庫
mysql_select_db(‘資料庫名字’);
//執行查詢,返回數據源
$query = mysql_query(“SELECT * FROM test”);
//遍曆數據源,並賦值給$r,當沒有數據時,變成false中斷循環
while($r = mysql_fetch_array($query)){
echo $r[‘field_name’];//輸出欄位
}
擴展資料:
mysql使用說明
1、如果是用 MySQL + Apache,使用的又是 FreeBSD 網路操作系統的話,安裝時候應按注意到FreeBSD的版本問題,在 FreeBSD 的 3.0 以下版本來說,MySQL Source 內含的 MIT-pthread 運行是正常的,但在這版本以上,必須使用 native threads,也就是加入一個 with-named-thread-libs=-lc_r 的選項。
2、如果在 COMPILE 過程中出了問題,請先檢查gcc版本是否在 2.81 版本以上,gmake 版本是否在3.75以上。
3、如果不是版本的問題,那可能是內存不足,請使用 ./configure–with-low-memory 來加入。
4、如果要重新做configure,那麼可以鍵入 rm config.cache 和 make clean 來清除記錄。
5、把 MySQL 安裝在 /usr/local 目錄下,這是預設值,也可以按照需要設定所安裝的目錄。
參考資料來源:百度百科-mySQL (關係型資料庫管理系統)
qt怎麼表格輸出mysql數據
1)創建ui界面 (2)導入頭文件 一、自動提交模式 二、手動提交模式 (1)構造函數中的代碼 (2) 「提交」按鈕的槽函數 在ui界面導入一個Table View。 這個控制項可以顯示錶格,在代碼中我們通過setHeaderData()函數可以自定義每列的名稱。 需要用到以下頭文件,QSqlDatabase用於連接資料庫,QMessageBox用於彈出對話框,QSqlError用於顯示資料庫的錯誤信息,QSqlQuery和QSqlTableModel用於操作資料庫。 #include QWidget #include QSqlDatabase #include QMessageBox #include QSqlError #include QString #include QSqlQuery #include QSqlTableModel 在Qt窗口顯示的表格中改動數據,然後點擊回車,資料庫中的表格中的數據就自動更新了。 注意,在這裡必須是敲擊回車才會進行資料庫的更新,如果直接用滑鼠切換到其他的地方是不會更新資料庫的。 //連接資料庫 QSqlDatabase db=QSqlDatabase::addDatabase(“QMYSQL”); db.setHostName(“127.0.0.1”); db.setUserName(“root”); db.setPassword(“123456”); db.setDatabaseName(“aaa2″); if(db.open()==false){ QMessageBox::warning(this,”waring”,db.lastError().text()); } //實例化model model = new QSqlTableModel(this); //將模型設置到視圖 ui-tableView-setModel(model); //給model設置數據表,前提條件是資料庫已經打開了 model-setTable(“student”);
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/183869.html