当前位置:首页 » 数据仓库 » mysql查看数据库语句
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

mysql查看数据库语句

发布时间: 2022-08-27 14:24:05

⑴ 如何查看Mysql数据库的create database语句

操作步骤

1、打开cmd,输入mysql -u 用户名 -p回车根据提示输入密码,如下图

⑵ 在mysql中怎么样查看数据库名

可以使用这两种方式查看数据库名:

1、用select database()语句;

2、用status语句,查询出来的结果中有一行是currrent database:***。这里***就

是当前所在的数据库名称。

1、打开mysql控制台,并输入密码;

⑶ mysql中查询数据库中表名称和结构的sql语句是什么啊啊

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 a < 10

  • ) select * from aa;

  • Query OK, 10 rows affected (0.00 sec)

  • Records: 10 Duplicates: 0 Warnings: 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 2G*************************** 1. row *************************** id: 1 select_type: SIMPLE table: t1 partitions: NULL type: ALLpossible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 10 filtered: 100.00 Extra: Using filesort1 row in set, 1 warning (0.00 sec)

  • 其实可以看到 TABLE 内部被 MySQL 转换为 SELECT 了。mysql-(ytt/3305)->show warningsG*************************** 1. row *************************** Level: Note Code: 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: 10 Duplicates: 0 Warnings: 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)

  • 注意:这里如果过滤的字段数量和子表数量不一致,则会报错。

⑷ 如何查看MySQL数据库的create database语句

打开cmd,输入mysql -u 用户名 -p回车根据提示输入密码,如下图

进入mysql数据库控制台,界面如下

查看当前数据库中存在那些数据库,使用show databases语句。如下:

使用show create database 数据库名 格式来查看数据库的详细创建信息。如下图:

通过在show create database语句后面追加 \G参数来格式化输出信息,便于查看。如下图:

⑸ 如何查看mysql数据库

查看当前使用的数据库,可使用如下命令
mysql> select database(); #使用函数database()
mysql> show tables; #列头信息中可看出当前使用的db,格式为:Tables_in_[db_name]
mysql> status; #注意结果中的"Current database:"信息

查看系统中有哪些数据库,
mysql> show databases;
更换当前使用的数据库,
mysql> use db_name;

返回当前数据库下的所有表的名称
mysql> show tables;
或者直接用如下命令
mysql> show tables from db_name;

查看表结构,可使用如下命令
mysql> desc 表名;
mysql> describe 表名;
mysql> show columns from 表名;
mysql> show create table 表名;
或者,
mysql> use information_schema
mysql> select * from columns where table_name='表名';

15个 MySQL 菜鸟问题

问题1:你如何确定 MySQL 是否处于运行状态?
答案: Debian 上运行命令 service mysql status,在RedHat 上运行命令 service mysqld status。然后看看输出即可。

问题2:如何开启或停止 MySQL 服务?
答案:运行命令 service mysqld start 开启服务;运行命令 service mysqld stop 停止服务。

问题3:如何通过 Shell 登入 MySQL?
答案:运行命令 mysql -u root -p

问题4:如何列出所有数据库?
答案:运行命令 show databases;

问题5: 如何切换到某个数据库并在上面工作?
答案:运行命令 use database_name; 进入名为 database_name 的数据库。

问题6:如何列出某个数据库内所有表?
答案:在当前数据库运行命令 show tables;

问题7:如何获取表内所有 Field 对象的名称和类型?
答案:运行命令 describe table_name;

问题8:如何删除表?
答案:运行命令 drop table table_name;

问题9:如何删除数据库?
答案:运行命令 drop database database-name;

问题10:如何查看表内所有数据?
答案:运行命令 select * from table_name;

问题11:如何从表(比如 oc_users )中获取一个 field 对象(比如 uid)的所有数据?
答案:运行命令 select uid from oc_users;

问题12:假设你有一个名为 ‘xyz’ 的表,它存在多个字段,如 ‘createtime’ 和 ‘engine’。名为 engine 的字段由 ‘Memoty’ 和 ‘MyIsam’ 两种数值组成。如何只列出 ‘createtime’ 和 ‘engine’ 这两列并且 engine 的值为 ‘MyIsam’?
答案:运行命令 select create_time, engine from xyz where engine = ”MyIsam”;

问题13:如何列出表 ‘xrt’ 内 name 域值为 ‘tecmint’,web_address 域值为 ‘tecmint.com’ 的所有数据?
答案:运行命令 select * from xrt where name = “tecmint” and web_address = “tecmint.com”;

问题14:如何列出表 ‘xrt’ 内 name 域值不为 ‘tecmint’,web_address 域值为 ‘tecmint.com’ 的所有数据?
答案:运行命令 select * from xrt where name != "tecmint" and web_address = "tecmint.com";

问题15:如何知道表内行数?
答案:运行命令 select count(*) from table_name;

⑹ MySQL如何查询当前正在运行的SQL语句

processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令
1.进入mysql/bin目录下输入mysqladmin processlist;
2.启动mysql,输入show processlist;

⑺ 在mysql中,查看已经存在数据库的spl语句是什么

查看当前用户的所有表:SELECT * FROM USER_TABLES;查看DBA用户下的所有表:SELECT * FROM DBA_TABLES;