在操作数据库之前,我们得先有一个数据库,在网上下载一个 mysql 的安装包,解压到自己一个空文件夹,设置好环境变量。如果不想这么麻烦,可以下载安装一个集成环境包,例如:phpstudy 。
在 MySQL 文件夹下面打开命令行,输入 mysql -u 用户名 -p 密码 -h 地址(本地搭建的话可以忽略这个选项)。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.53 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
在命令行下,每一个语句以 ' ; ' 结尾,在写完一个语句后,记得 ' ; ' 。
show databases; //列出所有的数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mm |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
在这几个数据库中,information_schema 数据库是 MySQL 系统自带的数据库,它提供了数据库元数据的访问方式。感觉 information_schema 就像是 MySQL 实例的一个百科全书,记录了数据库当中大部分我们需要了结的信息,比如字符集,权限相关,数据库实体对象信息,外检约束,分区,压缩表,表信息,索引信息,参数,优化,锁和事物等等。通过 information_schema 我们可以窥透整个 MySQL 实例的运行情况,可以了结 MySQL 实例的基本信息,甚至优化调优,维护数据库等。
查询语句
select 1,2,3,4,5,6,7........... 有几条数据就查询几条
select from * where
联合查询
union select (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=' table name '))
网友评论