在mysql里查看表,把表打出来的语句TABLE 语句
具体语法:TABLE table_name [ORDER BY column_name] [LIMIT number [OFFSET number]]
其实从语法上看 , 可以排序,也可以过滤记录集,不过比较简单,没有 SELECT 那么强大 。
示例 1
简单的建一张很小的表 y1,记录数为 10 条 。表 t1,插入 10 条记录
mysql-(ytt/3305)-create table t1 (r1 int,r2 int);
Query OK, 0 rows affected (0.02 sec)
mysql-(ytt/3305)-insert into t1
with recursive aa(a,b) as (
select 1,1
union all
select a+1,ceil(rand()*20) from aa where a10
) select * from aa;
Query OK, 10 rows affected (0.00 sec)
Records: 10Duplicates: 0Warnings: 0
简单全表扫描mysql-(ytt/3305)-select * from t1;+------+------+| r1| r2|+------+------+|1 |1 ||2 |9 ||3 |9 ||4 |17 ||5 |17 ||6 |16 ||7 |6 ||8 |1 ||9 |10 ||10 |3 |+------+------+10 rows in set (0.00 sec)
TABLE 结果mysql-(ytt/3305)-table t1;+------+------+| r1| r2|+------+------+|1 |1 ||2 |9 ||3 |9 ||4 |17 ||5 |17 ||6 |16 ||7 |6 ||8 |1 ||9 |10 ||10 |3 |+------+------+10 rows in set (0.00 sec)
看下 table 的执行计划mysql-(ytt/3305)-explain table t1 order by r1 limit 2\G*************************** 1. row ***************************id: 1select_type: SIMPLEtable: t1partitions: NULLtype: ALLpossible_keys: NULLkey: NULLkey_len: NULLref: NULLrows: 10filtered: 100.00Extra: Using filesort1 row in set, 1 warning (0.00 sec)
其实可以看到 TABLE 内部被 MySQL 转换为 SELECT 了 。mysql-(ytt/3305)-show warnings\G*************************** 1. row ***************************Level: NoteCode: 1003Message: /* select#1 */ select `ytt`.`t1`.`r1` AS `r1`,`ytt`.`t1`.`r2` AS `r2` from `ytt`.`t1` order by `ytt`.`t1`.`r1` limit 21 row in set (0.00 sec)
那其实从上面简单的例子可以看到 TABLE 在内部被转成了普通的 SELECT 来处理 。示例 2应用于子查询里的子表 。这里要注意,内表的字段数量必须和外表过滤的字段数量一致 。克隆表 t1 结构mysql-(ytt/3305)-create table t2 like t1;Query OK, 0 rows affected (0.02 sec)
克隆表 t1 数据mysql-(ytt/3305)-insert into t2 table t1;Query OK, 10 rows affected (0.00 sec)Records: 10Duplicates: 0Warnings: 0
table t1 被当做内表,表 t1 有两个字段,必须同时满足 t2 检索时过滤的字段也是两个 。mysql-(ytt/3305)-select * from t2 where (r1,r2) in (table t1);+------+------+| r1| r2|+------+------+|1 |1 ||2 |9 ||3 |9 ||4 |17 ||5 |17 ||6 |16 ||7 |6 ||8 |1 ||9 |10 ||10 |3 |+------+------+10 rows in set (0.00 sec)
注意:这里如果过滤的字段数量和子表数量不一致,则会报错 。
如何用java打印mysql数据库应该是连接数据库吧,这是连接数据库的步骤:
在开发环境中加载指定数据库的驱动程序 。
接下来的实验中,使用数据库MySQL , 所以需要下载MySQL支持JDBC的驱动程序(mysql-connector-java-5.1.18-bin.jar) 。
2. 开发环境是MyEclipse,将下载得到的驱动程序加载进开发环境中 。
3. 在Java程序中加载驱动程序 。
在Java程序中,通过 “Class.forName(“指定数据库的驱动程序”)”
方式来加载添加到开发环境中的驱动程序,例如Class.forName(“com.mysql.jdbc.Driver”) 。
4. 创建数据连接对象:通过DriverManager类创建数据库连接对象Connection 。
DriverManager类作用于Java程序和JDBC驱动程序之间,用于检查所加载的驱动程序是否可以建立连接,然后通过它的getConnection方法,根据数据库的URL、用户名和密码,创建一个JDBC
Connection 对象 。代码如:Connection connection =DriverManager.getConnection(“连接数据库的URL", "用户名",
"密码”) 。
其中 , URL=协议名+IP地址(域名)+端口+数据库名称;用户名和密码是指登录数据库时所使用的用户名和密码 。具体示例创建MySQL的数据库连接代码如下:
- mysql游标和存储过程是什么 mysql游标表名为变量
- 如何使用cmd命令行提示符登录mysql服务器 cmd中登陆mysql
- mysql怎么设置时区 mysql时间显示设置
- 招聘要精通mysql
- mysql 65535 8192 限制 mysql限制资源使用
- mysql有topn
- mysql协议包解析 mysqlicp协议
- mysql子查询和连接查询 mysql子查询插入
- Mysql使用索引查询 mysql使用round
- 云服务器游戏出现黑屏问题怎么解决? 云服务器游戏黑屏怎么办
