ubuntu升級R+RMySQL+manpage

來源:互聯網
上載者:User

ubuntu升級R+RMySQL+manpage 試了好些方法,以下成功了,記下備用sudo apt-add-repository -y "deb http://cran.rstudio.com/bin/linux/ubuntu `lsb_release -cs`/"sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9sudo apt-get updatesudo apt-get install r-base-dev在R中載入DBI,RMySQL兩個包,並使用dbConnect函數設定好使用者名稱和密碼library(RMySQL)con <- dbConnect(MySQL(),                 user='abc', # 使用者名稱                 password='abc', # 密碼                 dbname='abc', # 要使用的資料庫名稱                 host="localhost") # 主機地址dbListTables(con) # 列出所有資料庫中的表# 運行sql語句並返回資料到R data <- dbGetQuery(con, "select * from abc")SQL查詢可以通過dbSendQuery或dbGetQuery傳給資料庫管理系統。dbGetQuery傳送查詢語句,把結果以資料框形式返回。dbSendQuery傳送查詢,返回的結果是繼承"DBIResult"的一個子類的對象。"DBIResult"類可用於取得結果,而且還可以通過調用dbClearResult清除結果。函數fetch用於獲得查詢結果的部分或全部行,並以列表返回。函數dbHasCompleted確定是否所有行已經獲得了,而dbGetRowCount返回結果中行的數目。如果只是簡單的讀整個表,也可以用dbReadTable函數。  在設定串連時會在R語言環境中明文標示了資料庫使用者和密碼,為了安全起見,可以作如下設定:在本機目錄中定義一個配置文檔( ~/.my/cnf),例如定義兩個使用MySQL的使用者組:[local]user = rootpassword = ultra_secrethost = localhost [toto]user = capitaine_flampassword = galaxyhost = milky.way.net 然後在R中使用使用者組: library(RMySQL)con <- dbConnect(MySQL(), group='toto', dbname="user_profile")m <- dbGetQuery(con, "SELECT DISTINCT user_id FROM demographics WHERE gender='0'")dbDisconnect(con)另外R串連mysql會出現中文亂碼變問號情況,查到COS上一個貼子,解決方案如下: 在MySQL的設定檔/etc/mysql/my.cnf中[client]標籤下加default-character-set=utf8  MySQL:一旦安裝完成,MySQL 伺服器應該自動啟動。您可以在終端提示符後運行以下命令來檢查 MySQL 伺服器是否正在運行:1 sudo netstat -tap | grep mysql 講資料檔案許可權已變更位元所有使用者可讀寫chmod ugo+wrx **.csv csv匯入mysqlload data infile "/tmp/**.csv" into table 表名 fields terminated by "," lines terminated by '\n';mysql匯出到csvselect * from 表名 into outfile "/tmp/**.csv" fields terminated by "," lines terminated by '\n'; 內串連: select zgc_user_age.product_no,zgc_user_age.age from zgc_user_age inner join zgc_user_day on  zgc_user_age.product_no=zgc_user_day.product_no into outfile "/tmp/zgc_age_day.txt" fields terminated by "," lines terminated by '\n'; ubuntu的函數手冊頁不全,自己安裝:sudo apt-get install glibc-docman -k pthread或apropos pthread可以尋找到當前manpages中關於pthread的手冊sudo apt-get install manpages-posix manpages-posix-dev 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.