mysql資料庫讀寫操作源代碼(mysql資料庫讀寫操作源代碼查詢)

本文目錄一覽:

CentOS5.3 – mysql-6.0.10-alpha 源代碼和設置

1,下載mysql資料庫 源代碼 : mysql-6.0.10-alpha.tar.gz 2, 解壓 文件比較多,解壓也一段時間。 src]# tar vxzf mysql-6.0.10-alpha.tar.gz 3, 進入目錄進行 - 配置,編譯,安裝 ]# cd mysql-6.0.10-alpha 配置生成 makefile 文件 ]# ./configure –sysconfdir=/etc checking for termcap functions library… configure: error: No curses/termcap library found 出現錯誤,也就是生成 makefile 文件出錯了。 [root@localhost mysql-6.0.10-alpha]# make make: *** No targets specified and no makefile found. Stop. 如果你硬要輸入 make 命令是不行的,因為 makefile 根本沒有生成成功。 解決辦法: 我們加入 –with-named-curses-libs=/usr/lib/libncursesw.so.5 進行生成 makefile ./configure –sysconfdir=/etc –with-named-curses-libs=/usr/lib/libncursesw.so.5 Thank you for choosing MySQL! 看到這句話,生成 makefile 成功了。 下面進行make編譯: 需要的時間比較長。 ]# make 編譯安裝雖然花費的時間比較長,但是它應該可以適合任何一個發行版本的 Linux,編譯的中途過程我就不播放視頻出來了,截斷一部分。我現在已經編譯完成。 make[1]: Leaving directory `/opt/mysql-6.0.10-alpha/sql-bench’ Making all in win make[1]: Entering directory `/opt/mysql-6.0.10-alpha/win’ make[1]: Nothing to be done for `all’. make[1]: Leaving directory `/opt/mysql-6.0.10-alpha/win’ 最後進行安裝 ]# make install 編譯安裝完畢,有時候需要很長時間,如何判斷是否死機? 注意觀察主機的硬碟燈,編譯安裝時候 硬碟燈是一閃一閃的,有數據讀取。 下面拷貝配置文件 ]# cp /usr/local/share/mysql/my-large.cnf /etc/my.cnf 以後配置mysql ,就修改 /etc/my.cnf 即可 4, 初始化資料庫 # useradd -d /usr/local/var mysql # su – mysql $ /usr/local/bin/mysql_install_db 初始化出現錯誤。 Installing MySQL system tables… 090518 7:16:41 [ERROR] /usr/local/libexec/mysqld: unknown option ‘–skip-federated’ 090518 7:16:41 [ERROR] Aborting 090518 7:16:41 [Note] /usr/local/libexec/mysqld: Shutdown complete 我們解決辦法是,先 刪掉 /usr/local/var 下的 mysql 文件夾 rm -rf /usr/local/var/mysql 然後修改 vi /etc/my.cnf 找到skip-federated 注釋掉 ,也就是改成 ####skip-federated 然後保存退出 su – mysql 用會 mysql 身份, 來重新初始化 /usr/local/bin/mysql_install_db 這次成功了吧,沒有出現錯誤信息。 5, 啟動伺服器 [mysql@localhost var]$ /usr/local/bin/mysqld_safe 現在成功了, 用 netstat -tnl 看到 3306 熟悉的 mysql默認埠 6, 登陸測試 [mysql@localhost local]$ mysql -u root 成功的話, 出現 mysql mysql\s mysql\q 可以使用 show databases; 一般,如果你是編譯安裝mysql ,建議你像我下面的做法 提升為 root 用戶, su – cp /usr/local/share/mysql/mysql.server /etc/init.d/mysqld mysql 關閉的命令為:/etc/init.d/mysqld stop [root@localhost ~]# /etc/init.d/mysqld stop Shutting down MySQL.090518 07:26:41 mysqld_safe mysqld from pid file /usr/local/var/localhost.localdomain.pid ended SUCCESS! 就會顯示 關閉成功。 mysql 啟動的命令為:/etc/init.d/mysqld start [root@localhost ~]# /etc/init.d/mysqld start Starting MySQL. SUCCESS! 下面修改 伺服器啟動時候,就自動運行 mysql 6.0 vi /etc/rc.d/rc.local 我把它運行在 tomcat 前面, 然後保存退出。 ##################### 分隔 ###################### –查看資料庫的字符集 show variables like ‘character\_set\_%’; show variables like ‘collation_%’; 13:15 瀏覽(587) 評論(0) 分類: CentOS 2009-07-21 縮略顯示 CentOS5.3 編譯 mod_jk 1.2.15 鏈接器 整合apache httpd 和 tomcat關鍵字: centos mod_jk 現在我們來做一個整合,也就是當訪問 apache 80 埠時候 遇到 jsp 文件也可以正常訪問。 如果不整合, 你的apache 80 是不能運行jsp文件的, 只能使用8080埠,也就是tomcat 來訪問。 如何整合呢 ? 要藉助一個叫做 apache tomcat 的鏈接器。 下面是官方網站的下載地址,目前為止最新版是 1.2.15。。。 文章最後我會把這個工具提供下載,如果官方網站太慢的話。 首先下載 jakarta-tomcat-connectors-1.2.15-src.tar.gz 到伺服器 解壓 ]# tar xzvf jakarta-tomcat-connectors-1.2.15-src.tar.gz 注意是進入: jk/native 這個目錄 ]# cd jakarta-tomcat-connectors-1.2.15-src/jk/native 請確認你的 apache 的 apxs 文件位置 native]# ./configure –with-apxs=/usr/local/apache2/bin/apxs 編譯生成mod_jk native]# make 拷貝編譯完成生成的 mod_jk.so 文件, 這裡也是要注意你的apache modules 目錄位置 native]# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/ =============================================== 修改apache 配置文件 # vi /etc/httpd.conf 在DirectoryIndex中添加 index.jsp IfModule dir_module DirectoryIndex index.html index.jsp /IfModule 增加關於載入mod_jk的語句: LoadModule jk_module modules/mod_jk.so Include /usr/local/apache2/conf/mod_jk.conf 添加以下內容( 添加的時候去掉注釋,可能文件不能顯示中文 ): ###### 指出mod_jk模塊工作所需要的工作文件workers.properties的位置 JkWorkersFile /usr/local/apache2/conf/workers.properties ###### Where to put jk logs JkLogFile /usr/local/apache2/logs/mod_jk.log ###### Set the jk log level [debug/error/info] JkLogLevel info ###### Select the log format JkLogStampFormat “[%a %b %d %H:%M:%S %Y]” ###### JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories ###### JkRequestLogFormat set the request format JkRequestLogFormat “%w %V %T” ###### 將所有servlet 和jsp請求通過ajp13的協議送給Tomcat,讓Tomcat來處理 JkMount /servlet/* worker1 JkMount /*.jsp worker1 JkMount /*.do worker1 把一些注釋去掉吧,只些一些起作用的語句上去。保存退出。 =================================================== 在/usr/local/apache2/conf/ 下面 建立兩個配置文件mod_jk.conf和workers.propertie 注意: ( 如果沒有 conf 目錄,可以建立,因為我安裝時指定把 httpd.conf 放在 /etc 下的,就沒有 conf 目錄了 ) # vi mod_jk.conf 添加以下內容( 添加的時候去掉注釋,可能文件不能顯示中文 ): ###### 指出mod_jk模塊工作所需要的工作文件workers.properties的位置 JkWorkersFile /usr/local/apache2/conf/workers.properties ###### Where to put jk logs JkLogFile /usr/local/apache2/logs/mod_jk.log ###### Set the jk log level [debug/error/info] JkLogLevel info ###### Select the log format JkLogStampFormat “[%a %b %d %H:%M:%S %Y]” ###### JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories ###### JkRequestLogFormat set the request format JkRequestLogFormat “%w %V %T” ###### 將所有servlet 和jsp請求通過ajp13的協議送給Tomcat,讓Tomcat來處理 JkMount /servlet/* worker1 JkMount /*.jsp worker1 JkMount /*.do worker1 ———————————————————— # vi workers.properties 添加以下內容: ####### Defining a worker named worker1 and of type ajp13 worker.list=worker1 ####### Set properties for worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.worker1.lbfactor=50 worker.worker1.cachesize=10 worker.worker1.cache_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.socket_timeout=300 ——————- 我的tomcat 配置文件路徑: /usr/local/tomcat/conf/server.xml 最後編輯Tomcat的配置文件server.xml,在 Host 段中加入: Context path=”” docBase=”/usr/local/apache2/htdocs” debug=”0″ reloadable=”true” crossContext=”true”/ 重新啟動Apache和Tomcat。。。 [root@localhost bin]# ./shutdown.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/jdk1.7.0 [root@localhost bin]# ./startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/jdk1.7.0 # /usr/local/apache2/bin/apachectl stop # /usr/local/apache2/bin/apachectl start 剛才我在修改 httpd.conf 可能寫入了一些多餘信息 導致apache配置文件出錯,我注釋就可以了。 在/usr/local/apache2/htdocs/ 下 刪掉 index.html 建立一個index.jsp , 寫入一些簡單的內容: % out.println( “Hello ” ); % 用瀏覽器訪問伺服器 ,看到正確的頁面了。 說明apache 遇到jsp頁面 ,它可以提交給 tomcat 去處理。。。 18:21 瀏覽(315) 評論(0) 分類: CentOS 2009-07-21 縮略顯示 centos「You don’t have permission to access /index.html on this server.」關鍵字: centos Forbidden You don’t have permission to access /index.html on this server. 開始我以為我配置出錯,花半天時間都沒有搞定,今天終於搞定了. 原因:index.html是用root用戶建的文件,apache許可權不夠。 解決方法:更改文件許可權;chmod 755 index.html 17:09 瀏覽(498) 評論(0) 分類: CentOS 2009-07-17 縮略顯示 CentOS5.3 編譯安裝 apache 2.2.11 web伺服器(httpd-2.2.11.tar.gz)關鍵字: centos apache (現檢測是否已經安裝apapche,如果有的話請卸載後重新安裝) 1, 首先你必須下載 : httpd-2.2.11.tar.gz 當然你也可以到官方 上下載。 2, 解壓 src]# tar vxzf httpd-2.2.11.tar.gz 3, 進入目錄 # cd httpd-2.2.11 httpd-2.2.11]# ./configure –sysconfdir=/etc –enable-ssl –enable-modules 配置文件放在 /etc 下 no SSL-C headers found configure: error: …No recognized SSL/TLS toolkit detected 沒有ssl 我們,生成makefile 文件失敗,以後再安裝 openssl 也可以 httpd-2.2.11]# ./configure –sysconfdir=/etc –enable-modules 好,這次沒有發現什麼錯誤, –enable-modules 這個強烈建議加上, 也就是說 以後apache 可以添加其他的模塊,方便很多。 下面進行編譯,make編譯 需要一定的時間,不過比起編譯mysql要快些。 httpd-2.2.11]# make 下面進行安裝 httpd-2.2.11]# make install 安裝完成了。。。 4, 啟動服務 測試一下吧。 ]# /usr/local/apache2/bin/apachectl start # netstat -tnl 可以看到 80 埠,說明apache啟動了。 tcp 0 0 :::80 :::* LISTEN 打開瀏覽器進行訪問吧。 # ifconfig 查看 Linux 伺服器ip地址。 inet addr:192.168.138.128 看到It works! 說明正常工作了 cd /usr/local/apache2/ 可以看到 htdocs 就是 web 伺服器的 目錄所在 你可以想我這樣 vi test.html 上面寫一些信息,然後進行訪問。 讓Apache 自動啟動 # echo “/usr/local/apache2/bin/apachectl start ” /etc/rc.local (或者手動在/etc/rc.d/rc.local中設置) 好,然後重啟伺服器,就可以發現 apache 自動啟動了

你有一個簡單的資料庫的源代碼嗎?最好用Java實現的…

class ConnectionProvider{

private static String JDBC_DRIVER;

private static String DB_URL;

private static String DB_USER;

private static String DB_PASSWORD;

public ConnectionProvider()

{

JDBC_DRIVER = “com.mysql.jdbc.Driver”

DB_URL = “jdbc:mysql://localhost:3306/u-disk”;

DB_USER = “root”;

DB_PASSWORD = “root”

};

public Connection getConnection()

{

try {

Class.forName(JDBC_DRIVER);

} catch (Exception e) {

System.out.println(“驅動文件路徑有誤!”);

}

}

Connection con = null;

try {

con = DriverManager.getConnection(DB_URL, DB_USER,

DB_PASSWORD);

} catch (SQLException e) {

System.out.println(“資料庫連接建立異常!\n@shy2850@” + e.getMessage() +

e.getCause());

}

System.out.println(“得到連接:Connection ” + ConnectionPool.connections.size() + 1);

return new ConnectionImpl(con);

}

}

可以使用這個包裝的資料庫連接數據源在DAO工具類中使用:

package com.jdbc;

import java.sql.*;

/**課題:封裝資料庫的增刪改查的工具類的實現。

*

* 假設相關資料庫的表結構如下:

* 表名:user

* 列名及屬性:id(int 自增),name(varchar(20)),tele(char(12)),birthday(date)

* @author shy2850

*/

public class UserDAO {

Connection conn;

public UserDAO(Connection conn) {

this.conn = conn;

}

public int save(User user) throws SQLException {

String sql = “insert into user values(0,?,?,?)”;

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setString(1, user.getName());

pstmt.setString(2, user.getTele());

pstmt.setDate(3, user.getBirthday());

int n = pstmt.executeUpdate();

pstmt.close();

return n;

}

public int delete(User user) throws SQLException{

String sql = “delete from user where id = “+user.getId();

Statement stmt = conn.createStatement();

int n = stmt.executeUpdate(sql);

stmt.close();

return n;

}

public int update(User user) throws SQLException{

String sql = “update user set name=?, tele=?, birthday=? where id = “+user.getId();

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setString(2, user.getName());

pstmt.setString(3, user.getTele());

pstmt.setDate(4, user.getBirthday());

int n = pstmt.executeUpdate(sql);

pstmt.close();

return n;

}

public User getUser(Integer id) throws SQLException{

String sql = “select * from user where id = ” + id;

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

User user = getUserFromResultSet(rs);

rs.close();

stmt.close();

return user;

}

static User getUserFromResultSet(ResultSet rs) throws SQLException{

Integer id = rs.getInt(“id”);

String name= rs.getString(“name”);

String tele= rs.getString(“tele”);

Date birthday = rs.getDate(“birthday”);

return new User(id, name, tele, birthday);

}

}

/**

* 構建資料庫表的java類映射

*/

class User{

private Integer id;

private String name;

private String tele;

private Date birthday;

public User() {

}

public User(Integer id, String name, String tele, Date birthday) {

super();

this.id = id;

this.name = name;

this.tele = tele;

this.birthday = birthday;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getTele() {

return tele;

}

public void setTele(String tele) {

this.tele = tele;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

}

如何下載mysql資料庫源代碼

mysql官方網站就有呀:,選擇source

code

或者你到這個網站上去下載:,到這個網址,右邊有個查看講義資料,那個裡面就有

原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/129496.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
簡單一點的頭像簡單一點
上一篇 2024-10-03 23:26
下一篇 2024-10-03 23:26

相關推薦

  • 如何修改mysql的埠號

    本文將介紹如何修改mysql的埠號,方便開發者根據實際需求配置對應埠號。 一、為什麼需要修改mysql埠號 默認情況下,mysql使用的埠號是3306。在某些情況下,我們需…

    編程 2025-04-29
  • Python棧操作用法介紹

    如果你是一位Python開發工程師,那麼你必須掌握Python中的棧操作。在Python中,棧是一個容器,提供後進先出(LIFO)的原則。這篇文章將通過多個方面詳細地闡述Pytho…

    編程 2025-04-29
  • g3log源代碼學習

    g3log是一個高性能C++日誌庫,其代碼十分精簡和可讀性強,本文將從3個方面詳細介紹g3log源代碼學習。 一、g3log源代碼整體架構 g3log的整體架構十分清晰,其中有3個…

    編程 2025-04-29
  • Python 常用資料庫有哪些?

    在Python編程中,資料庫是不可或缺的一部分。隨著互聯網應用的不斷擴大,處理海量數據已成為一種趨勢。Python有許多成熟的資料庫管理系統,接下來我們將從多個方面介紹Python…

    編程 2025-04-29
  • openeuler安裝資料庫方案

    本文將介紹在openeuler操作系統中安裝資料庫的方案,並提供代碼示例。 一、安裝MariaDB 下面介紹如何在openeuler中安裝MariaDB。 1、更新軟體源 sudo…

    編程 2025-04-29
  • Python操作數組

    本文將從多個方面詳細介紹如何使用Python操作5個數組成的列表。 一、數組的定義 數組是一種用於存儲相同類型數據的數據結構。Python中的數組是通過列表來實現的,列表中可以存放…

    編程 2025-04-29
  • Python操作MySQL

    本文將從以下幾個方面對Python操作MySQL進行詳細闡述: 一、連接MySQL資料庫 在使用Python操作MySQL之前,我們需要先連接MySQL資料庫。在Python中,我…

    編程 2025-04-29
  • Python代碼實現迴文數最少操作次數

    本文將介紹如何使用Python解決一道經典的迴文數問題:給定一個數n,按照一定規則對它進行若干次操作,使得n成為迴文數,求最少的操作次數。 一、問題分析 首先,我們需要了解迴文數的…

    編程 2025-04-29
  • Python磁碟操作全方位解析

    本篇文章將從多個方面對Python磁碟操作進行詳細闡述,包括文件讀寫、文件夾創建、刪除、文件搜索與遍歷、文件重命名、移動、複製、文件許可權修改等常用操作。 一、文件讀寫操作 文件讀寫…

    編程 2025-04-29
  • 資料庫第三範式會有刪除插入異常

    如果沒有正確設計資料庫,第三範式可能導致刪除和插入異常。以下是詳細解釋: 一、什麼是第三範式和範式理論? 範式理論是關係資料庫中的一個規範化過程。第三範式是範式理論中的一種常見形式…

    編程 2025-04-29

發表回復

登錄後才能評論