MySQL est un système de gestion de base de données (SGDB). Selon le type d'application, sa licence est libre ou propriétaire. Il fait partie des logiciels de gestion de base de données les plus utilisés au monde, autant par le grand public (applications web principalement) que par des professionnels, au même titre que Oracle ou SQL Server 1).
Type | Bytes | Signé | Non-signé |
---|---|---|---|
TINYINT | 1 | -128 → 127 | 0 → 255 |
SMALLINT | 2 | -32768 → 32767 | 0 → 65535 |
MEDIUMINT | 3 | -8388608 → 8388607 | 0 → 16777215 |
INT | 4 | -2147483648 → 2147483647 | 0 → 4294967295 |
BIGINT | 8 | -9223372036854775808 → 9223372036854775807 | 0 → 18446744073709551615 |
CREATE SCHEMA nom_schemas;
CREATE DATABASE `new_vid` CHARACTER SET `utf8` COLLATE `utf8_general_ci`;
> USE nom_bd; > GRANT ALL privileges ON *.* TO 'stephane'@'%' IDENTIFIED BY 'l9s-jDhb9_SQ'; > FLUSH privileges;
CREATE TABLE users ( id INT AUTO_INCREMENT, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL, email VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id) );
public void InsertMySQL(string city, int country_id) { MySqlConnection oConn = new MySqlConnection("Database=prometo;Data Source=localhost;User id=root;Password=root"); oConn.Open(); MySqlCommand command = new MySqlCommand("insert into city(city, country_id ) select ?city, ?country_id", oConn); command.Parameters.Add(new MySqlParameter("?city", MySqlDbType.VarChar, 50)); command.Parameters.Add(new MySqlParameter("?country_id", MySqlDbType.Int16)); command.Parameters[0].Value = city; command.Parameters[1].Value = country_id; command.ExecuteNonQuery(); oConn.Close(); }
public void Mysql_File_Save(string sConnString, int nCustId, byte[] bData, string sName, string sContentType, int nContentLength) { using (MySqlConnection oConn = new MySqlConnection(sConnString)) { oConn.Open(); MySqlCommand oCommand = oConn.CreateCommand(); oCommand.Connection = oConn; //Add new oCommand.CommandText = "insert into cust_file(customer_id, filename, filedata, contenttype, length) " + "values( ?in_customer_id, ?in_filename, ?in_filedata, ?in_contenttype, ?in_length)"; MySqlParameter oParam = oCommand.Parameters.Add("?in_customer_id", MySqlDbType.Int64); oParam.Value = nCustId; oParam = oCommand.Parameters.Add("?in_filename", MySqlDbType.VarChar, 255); oParam.Value = sName; oParam = oCommand.Parameters.Add("?in_filedata", MySqlDbType.Blob); oParam.Value = bData; oParam = oCommand.Parameters.Add("?in_contenttype", MySqlDbType.VarChar, 255); oParam.Value = sContentType; oParam = oCommand.Parameters.Add("?in_length", MySqlDbType.Int64); oParam.Value = nContentLength; oCommand.ExecuteNonQuery(); oConn.Close(); } }
Il faut pouvoir prendre le fichier et le mettre dans un tableau.
byte[] bData = FileToArray("f:\\n1jpg.jpg"); Mysql_File_Save("Database=dbfichiers;Data Source=localhost;User id=root;Password=root", 1, bData, "N1jpg", MimeType("f:\\n1jpg.jpg"), bData.Length);
public DataTable GetData_MySQLBinary() { MySqlConnection oConn = new MySqlConnection(); oConn.ConnectionString = "Database=fichiers;Data Source=localhost;User id=root;Password=root"; oConn.Open(); DataSet oDataSet = new DataSet("tab1"); //Get data MySqlCommand command = new MySqlCommand("select * from cust_file", oConn); MySqlDataAdapter oAdapter = new MySqlDataAdapter(command); oAdapter.Fill(oDataSet, "tab1"); DataTable dt = oDataSet.Tables["tab1"]; oConn.Close(); return dt; }
DataTable dt = GetData_MySQLBinary(); if (dt.Rows.Count > 0) { byte[] bData2 = (byte [])dt.Rows[0]["filedata"]; System.IO.MemoryStream oStream = new System.IO.MemoryStream(bData2); pictureBox1.Image = Image.FromStream(oStream); }
alter table tablename charset=utf8;
CASE WHEN `User`.`firstname` IS NULL THEN `User`.`username` WHEN `User`.`firstname` IS NOT NULL THEN (CONCAT(`User`.`firstname`, " ", `User`.`lastname`)) END
CASE `User`.`show_fullname` WHEN 1 THEN IF((`User`.`firstname` IS NULL) OR (`User`.`lastname` IS NULL), `User`.`username`, CONCAT(`User`.`firstname`, " ", `User`.`lastname`)) WHEN 0 THEN `User`.`username` END
CASE `User`.`show_fullname` WHEN 1 THEN `User`.`name` WHEN 0 THEN `User`.`username` END
La documentation de l'interface commande de mysql se trouve sur la page The MySQL Command-Line Client.
Se connecter (le -p
désigne la base de données, non pas le password):
$ mysql -u root -p <db_name> Enter password: <user password>