找到 4219 篇文章 相关 MySQLi
2K+ 次查看
INTERVAL 关键字与 NOW() 和 CURDATE() MySQL 函数的使用方式与日期值的时、日或日期时间单位类似。示例使用 INTERVAL 与 MySQL NOW()mysql> Select NOW() + INTERVAL 2 day; +------------------------+ | NOW() + INTERVAL 2 day | +------------------------+ | 2017-10-30 09:19:31 | +------------------------+ 1 row in set (0.00 sec) mysql> Select NOW() - INTERVAL 2 day; +------------------------+ | NOW() - INTERVAL 2 day | +------------------------+ | 2017-10-26 09:19:45 | +------------------------+ 1 row in set (0.00 sec) mysql> Select NOW() - INTERVAL 2 hour; +-------------------------+ | NOW() ... 阅读更多
264 次查看
就像我们检查过 MySQL 数据库的尺寸一样,我们也可以检查特定数据库中表的尺寸。可以通过以下方式实现:mysql> SELECT -> table_name AS "Table", -> round(((data_length + index_length) / 1024 / 1024), 2) as SIZE -> FROM information_schema.TABLES -> WHERE table_schema = "SAMPLE" -> ORDER BY SIZE; +-------------+-------+ | Table | SIZE | +-------------+-------+ | employee | 0.02 | | student | 0.02 | | new_student | 0.02 | +-------------+-------+ 3 rows in set (0.00 sec)此输出显示了 Sample 数据库中三个表的尺寸。
114 次查看
实际上,MySQL 的行为取决于 allow_invalid_dates 模式。如果启用此模式,则 MySQL 将接受无效日期,并像处理有效日期一样执行日期运算。否则,如果此模式处于非活动状态,则它将不接受无效日期,并将输出 NULL。mysql> select '2017-02-30' + INTERVAL 7 day; +-------------------------------+ | '2017-02-30' + INTERVAL 7 day | +-------------------------------+ | NULL ... 阅读更多
76 次查看
我们可以借助以下语句检查所有 MySQL 数据库的尺寸mysql> SELECT table_schema "Database", -> SUM(data_length + index_length)/1024/1024 "Size in MB" -> FROM information_schema.TABLES GROUP BY table_schema; +--------------------+----------------+ | Database | Size in MB | +--------------------+----------------+ | gaurav | 1.04785156 | | information_schema | 0.00878906 | | mysql | 0.68551350 | | performance_schema | 0.00000000 | | sample | 0.04687500 | | tutorial | 0.03125000 | +--------------------+----------------+ 6 rows in set, 1 warning (0.33 sec)
1K+ 次查看
顾名思义,CURDATE() 函数将返回当前日期。简单来说,我们可以说它只返回日期,不返回时间。mysql> select CURDATE(); +------------+ | CURDATE() | +------------+ | 2017-10-28 | +------------+ 1 row in set (0.00 sec)相反,NOW() 函数将返回当前日期和时间。mysql> Select NOW(); +---------------------+ | NOW() | +---------------------+ | 2017-10-28 09:10:16 | +---------------------+ 1 row in set (0.00 sec)
80 次查看
以下语句显示了 Sample 数据库中包含“email”列的两个表的列表:mysql> SELECT DISTINCT TABLE_NAME -> FROM INFORMATION_SCHEMA.COLUMNS -> WHERE COLUMN_NAME IN('EMAIL') -> AND TABLE_SCHEMA = 'SAMPLE'; +---------------+ | TABLE_NAME | +---------------+ | employee | | new_student | +---------------+ 2 rows in set (0.04 sec)
497 次查看
MySQL 可以通过将 INTERVAL 关键字与时间、日期或日期时间单位结合起来,使用加法和减法运算符执行日期运算。示例 1将 2 天添加到特定日期。mysql> Select '2017-05-20' + INTERVAL 2 day; +-------------------------------+ | '2017-05-20' + INTERVAL 2 day | +-------------------------------+ | 2017-05-22 | +-------------------------------+ 1 row in set (0.00 sec)示例 2从特定日期减去 2 天。mysql> Select '2017-05-20' - INTERVAL 2 day; +-------------------------------+ | '2017-05-20' - INTERVAL 2 day | +-------------------------------+ | 2017-05-18 | +-------------------------------+ 1 row in ... 阅读更多
132 次查看
当我们尝试对存储在表中的日期值执行此类运算时,MySQL 会将日期值视为数字并执行算术运算。假设我们有一个名为“example”的表,其中“orderdate”列包含日期值,则以下算术运算将阐明上述内容:mysql> select * from example; +------------+ | orderdate | +------------+ | 2017-05-25 | +------------+ 1 row in set (0.00 sec) mysql> select orderdate+10 from example; +--------------+ | orderdate+10 | +--------------+ | 20170535 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate*10 from example; ... 阅读更多
108 次查看
借助 CREATE DATABASE db-name 命令,我们可以检查创建任何 MySQL 数据库的语句。mysql> SHOW CREATE DATABASE Sample; +----------+-------------------------------------------------------------------+ | Database | Create Database | +----------+-------------------------------------------------------------------+ | sample | CREATE DATABASE `sample` /*!40100 DEFAULT CHARACTER SET latin1 */ | +----------+-------------------------------------------------------------------+ 1 row in set (0.00 sec)输出显示了名为 Sample 的 MySQL 数据库是如何创建的。