跳到主要內容

發表文章

目前顯示的是有「MySQL」標籤的文章

using Entity Framework 6 with MySQL databases

To start working with VS 2013 and EF 6  1- Install the MySQL for Visual Studio 1.1.1  2- Install the Connector/Net 6.8.1 product.  3- To work with Database first please do the following  a. Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.  b. Add the provider to your app/web config file on the providers for Entity Framework section with the following line:  [provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"][/provider] c. Before you run the Wizard compile your application so the new changes are applied.  4- To work with Model First please do the following  a. Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.  b. Add the ADO.Net Entity Model new or existing.  c. Select the T4 template corresponding to MySQL (SSDLToM...

[SQL] SQL依照你的排序條件 找出目前資料的前一筆與下一筆。 Find Pre and Next DataRows of current Datarow by your order condition

有時候需要用SQL找出前一筆跟後一筆資料 用SQL的TOP是沒有辦法做到 這個時候就可以這個語法 select * from ( SELECT TOP 1 * FROM [Article] where Poid {CurrentPoid} order by CreateDate ASC) t2 找出目前PK id前一個與後一個的資料(依照想要排序順序) 那如果指示想要一個資料行呈現的話 可以改用下面的SQL語法 讓這兩筆資料join在同一筆 select Pre.*,Nex.* from (SELECT TOP 1 * ,1 tID FROM [dbo].[Article] where Poid {CurrentPoid} order by CreateDate ASC) Nex on Pre.tID=Nex.tID

[MySQL] 重設MySQL root 密碼 / Rest MySQL root password

關閉執行中的MySQL 以系統管理員打開cmd視窗 換到MySQL的安裝路徑的bin資料夾內執行 執行mysqld --skip-grant-tables, 以這個指令啟動mysql,會跳過權限檢查。 另外再開一個cmd視窗 一樣換到mysql安裝路徑中bin資料夾內,啟動mysql 在 mysql> 下 執行 update mysql.user set password=PASSWORD('1234') where user='root'; flush privileges; quit; 將密碼設定成1234 重新啟動MySql即可

查詢MS SQL Server中Table space使用的狀況

一般用户或者DBA都會經常需要檢查所有的DB或Table的容量狀況 在MS SQL Server 中查詢的方法有有 方法1: select object_name(id) tablename,8*reserved/1024 reserved, rtrim(8*dpages/1024)+'Mb' used,8*(reserved-dpages)/1024 unused, 8*dpages/1024-rows/1024*minlen/1024 free,rows,* from sysindexes where indid=1 order by reserved desc 方法2: exec sp_MSforeachtable "exec sp_spaceused '?'" 註解 系统預存函數sp_MSforeachtable和sp_MSforeachdb,是Microsoft提供的兩個不公開的函數,從MS SQL Server 6.5開始存放在SQL Server的MASTER DB中 http://www.seekeep.com/html/computer/database/mssql/200802/628.html

[MySQL]MySQL的conv函数(字串數字轉換整數數字)

CONV(N,from_base,to_base) N是要轉換的數據,from_base是原進制,to_base是目標進制。 這個function通常用在進制轉換 但是有個如果在資料庫中原本的數字數據存放類型是用字串 可是卻需要作些運算計算的話 可以用這個函數來將資料的強制轉換 CONV("20",10,10) 字面上的意思是將20以十進位轉換成十進位 所以回傳的時候 當然就是20囉 而不是"20"

[MySQL]MySQL Alter Add/Drop Constraint語法

Add ALTER TABLE [$DBName].[$Table] ADD CONSTRAINT [$Constraint_Name] FOREIGN KEY [$Constraint_Name] ([$ColumnName]) REFERENCES [$RefTable] ([$ColumnName]) {ON DELETE [NO ACTION/CASCADE/SET NULL/RESTRICT]} {ON UPDATE [NO ACTION/CASCADE/SET NULL/RESTRICT]}; Drop ALTER TABLE [$DBName].[$Table] DROP FOREIGN KEY [$Constraint_Name] ;

[MySQL] MySQL備份與還原

MySQL 備份資料庫有兩種方法,一種是土法煉鋼法,就是直接把 /usr/local/mysql/data/[資料庫名稱]/* 備份,然後放回另一個 MySQL 的資料庫路徑裡,不過資料庫版本要一樣喔,以免發生非預期的結果。 PS. 第一個方法備份還原時最好先把 mysqld 停下來。 要看 MySQL 是否執行中可下: /usr/local/mysql/bin/mysqladmin status 另一種感覺較正規的作法就是用 mysqldump 把資料倒出來 *.sql,指令格式如下: mysqldump --user=[資料庫使用者] -p [資料庫名稱] > [備份檔名].sql Example: mysqldump --user=root -p wordpress > /Users/home/wordpress.sql 完成後你就會在 /Users/home/ 得到 wordpress.sql,把這個 .sql 上傳到你要轉移的主機上 注意喔,如果要還原回去的 MySQL 中不存在這個資料庫時,會發生這樣的錯誤: mysql --user=root -p wordpress create database wordpress; Query OK, 1 row affected (0.00 sec) 離開資料庫 mysql> quit 接著準備匯入了,匯入的指令格式: mysql -h [mysqlhostserver] -u [資料庫使用者] -p [資料庫名稱] mysqldump --user=root -p wordpress 註:我沒用到 -h [mysqlhostserver] 這個參數。 這樣囉!收工。