Preliminary MySQL Study Notes

 

Some useful functions...
mysql> select version(), database(), user(), curdate(), now();
+-----------+------------+----------------+------------+---------------------+
| version() | database() | user() | curdate() | now() |
+-----------+------------+----------------+------------+---------------------+
| 5.5.10 | test | ODBC@localhost | 2012-03-07 | 2012-03-07 22:09:04 |
+-----------+------------+----------------+------------+---------------------+
1 row in set (0.00 sec)

mysql> select current_date;
+--------------+
| current_date |
+--------------+
| 2012-03-07 |
+--------------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| pet |
| shop |
+----------------+
2 rows in set (0.05 sec)

mysql>

 

show table schema and ddl (desc, show create table) ...
mysql> desc pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.02 sec)

mysql> show create table pet \G
*************************** 1. row ***************************
Table: pet
Create Table: CREATE TABLE `pet` (
`name` varchar(20) DEFAULT NULL,
`owner` varchar(20) DEFAULT NULL,
`species` varchar(20) DEFAULT NULL,
`sex` char(1) DEFAULT NULL,
`birth` date DEFAULT NULL,
`death` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

 

Convinient INSERT statement...
mysql> create table shop
-> ( article int(4) unsigned zerofill default '0000' not null,
-> dealer char(20) default '' not null,
-> price double(16, 2) default '0.00' not null,
-> primary key(article, dealer));
Query OK, 0 rows affected (0.17 sec)

mysql> select * from shop;
Empty set (0.00 sec)

mysql> insert into shop values
-> (1, 'A', 3.45),
-> (1, 'B', 3.99),
-> (2, 'A', 10.99),
-> (3, 'B', 1.45),
-> (3, 'C', 1.69),
-> (3, 'D', 1.25),
-> (4, 'D', 19.95);
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> select * from shop;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0001 | A | 3.45 |
| 0001 | B | 3.99 |
| 0002 | A | 10.99 |
| 0003 | B | 1.45 |
| 0003 | C | 1.69 |
| 0003 | D | 1.25 |
| 0004 | D | 19.95 |
+---------+--------+-------+
7 rows in set (0.00 sec)

load data into a table -- "LOAD DATA LOCAL INFILE xxx INTO table xxx"
mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
-> LINES TERMINATED BY '\r\n';


(On an Apple machine running OS X, you would likely want to use LINES TERMINATED BY '\r'.)

 

 AUTO_INCREMENT (similar to Oracle Sequence)....
mysql> create table animals
-> ( id mediumint not null AUTO_INCREMENT,
-> name char(30) not null,
-> primary key(id)
-> ) engine=MyISAM;
Query OK, 0 rows affected (0.06 sec)

mysql> insert into animals(name) values
-> ('dog'), ('cat'), ('penguin');
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from animals;
+----+---------+
| id | name |
+----+---------+
| 1 | dog |
| 2 | cat |
| 3 | penguin |
+----+---------+
3 rows in set (0.00 sec)
 
  


mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.03 sec)

 

mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;

 
 

BIT_COUNT(), BIT_OR()...
SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
GROUP BY year,month;

 

mysqld - (mysql daemon -- The MySQL Server)

When MySQL server starts, it listens for network connections from client programs and manages access to database on behalf of those clients.

 

 MySQL Storage Engine

 

InnoDB Strorage Engine

  - Overview of InnoDB Tablespace and Log Files

  Two important disk-based resources managed by the InnoDB storage engine are its tablespace data files and its log files. If you specify no InnoDB configuration options, MySQL creates an auto-extending 10MB datafile named "ibdata1" and two 5MB log files named "ib_logfile0" and "ib_logfile1" in the MySQL data directory.

 

Enabling and Disabling Multiple Tablespaces

To enable multiple tablepspaces, start the server with the "--innodb_file_per_table" option.

[mysqld]
innodb_file_per_table

 

Or, can set the variable globally and move the table from the system tablespace to its own tablespace or vice versa.

-- Move table from system tablespace to its own tablespace.
SET GLOBAL innodb_file_per_table=1;
ALTER TABLE table_name ENGINE=InnoDB;
-- Move table from its own tablespace to system tablespace.
SET GLOBAL innodb_file_per_table=0;
ALTER TABLE table_name ENGINE=InnoDB;


InnoDB always needs the shared tablepace because it puts its internal data dictionary and undo logs there. The .ibd files are not sufficient for InnoDB to operate.

When a table is moved out of the system tablespace into its own .ibd file, the data files that make up the system tablespace remain the same size. The space formerly occupied by the table can be reused for new InnoDB data, but is not reclaimed for use by the OS. 

 

Query Transaction/lock in innodb

There are 3 tables in INFORMATION_SCHEMA database -- INNODB_TRX, INNODB_LOCKS and INNODB_LOCK_WAITS

There is one column in the table INNODB_TRX -- trx_weight, which reflects the number of rows locked in the transaction. If deadlock happens, the transaction with lower trx_weight will be rollbacked by innodb engine.

 

 

 

 

 

转载于:https://www.cnblogs.com/fangwenyu/archive/2012/07/08/2382677.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 初步的传感器是指最初的传感器,用于感知和测量环境中的物理量、化学量或生物量。这些传感器通常用于收集数据,以便进行进一步的分析和处理。 初步的传感器可以用于各种不同的应用领域,如环境监测、工业自动化、医疗诊断等。它们可以测量温度、湿度、压力、光照、声音等物理量,也可以测量气体浓度、水质、土壤成分等化学量,甚至可以测量心率、血压等生物量。 初步的传感器通常具有小巧、便携和低功耗的特点,以便于安装和使用。它们可以通过有线或无线的方式将收集到的数据传输给数据处理单元,然后进一步进行分析和应用。 初步的传感器的性能和精度通常较低,但在一些应用场景中足够使用。在进行精确测量或要求高度一致性的场景中,可能需要更复杂、更高精度的传感器来满足要求。 总之,初步的传感器是最早的传感器,用于感知和测量环境中各种物理、化学或生物的量。它们可以广泛用于各个领域,为数据采集和分析提供基础。随着科技的发展和需求的增加,传感器技术也越来越精细和复杂。 ### 回答2: Preliminary 传感器是一种用于收集初步信息或进行初步测量的传感器。它主要用于确认和验证数据,并为后续的研究和分析提供依据。 Preliminary 传感器可以通过使用多种技术来获取数据,包括光学、声波、电磁和加速度等。它可以测量环境中的不同参数,如温度、湿度、压力、光照和运动等。 与其他高精度传感器相比,preliminary 传感器通常具有较低的测量精确度和准确性。尽管如此,它们仍然可以提供足够的信息来评估某个环境或系统的基本特性。 preliminary 传感器通常应用于许多领域。在环境监测方面,它可以用于检测空气质量、水质、土壤含水量等,以便评估环境的健康状况。在工业应用中,preliminary 传感器可以帮助监测和控制生产过程中的温度、压力和湿度等参数,以确保产品质量和工艺稳定性。 此外,preliminary 传感器还可以用于智能家居系统,例如自动灯光控制和温度调节。它们可以通过监测周围环境的状态并与设定的条件进行比较,实现自动化控制和能源节约。 总而言之,preliminary 传感器提供了初步收集数据和测量环境参数的功能。尽管其测量精度较低,但它们可以在各种领域中发挥重要作用,为后续的研究和分析提供重要的参考依据。 ### 回答3: 初步传感器是指在某个领域或某项工作中,在进行深入研究或正式操作之前使用的传感器。这种传感器可以帮助人们对待测对象进行初步的观察、测量或监测。 初步传感器通常具有以下特点: 1. 快捷简易:初步传感器操作方便、使用简单。其设计和功能主要针对对待测对象的初步了解和探索,不需要过多的专业知识或复杂的操作步骤。 2. 低成本:初步传感器通常相对便宜,成本低廉。这样可以降低对待测对象的测试成本,以及在初步阶段对传感器的投入。 3. 多功能:初步传感器一般具备多种功能,可以根据不同需求进行测量、观测和监测。可以针对特定目标进行调整和适应,提供初步的数据和信息。 4. 基础应用:初步传感器广泛应用于科学研究、实验室试验、工程项目等领域。在进行具体实验或操作之前,可以通过初步传感器获得一些对象的基本特征或性质。这对进一步的研究和操作具有重要意义。 总之,初步传感器是一种方便、简单、低成本且多功能的传感器,可以在不破坏或影响待测对象的前提下,提供初步的观测、测量或监测数据。通过初步传感器的使用,人们可以更好地了解被测对象的性质和特征,为随后的研究或操作提供基础信息和决策依据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值