mysql概述及基本语法
Posted golinux
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql概述及基本语法相关的知识,希望对你有一定的参考价值。
一.mysql概述
一个dbms中可以有多个数据库,一个数据库中可以有多张数据表表,我们的数据实际就是存储在数据表中
dbms 数据库管理系统
database 数据库
table 数据表
field 字段,也就是数据表的列
record 记录,数据表中每一行就是一个记录
二.mysql语句
1.语句分类
DDL(data definition language) 数据定义语言,就是创建/修改/查询/删除数据库,创建/修改/查询/删除数据表之类的操作,create,alter drop,show..
DML(data manipulation language) 数据操纵语言,就是添加/修改/查询/删除数据的语句,insert update select delete..
DCL(data control language) 数据控制语言,控制数据库,数据表,用户等的访问权限
2.mysql中求帮助
mysql> help; mysql> ?
mysql> ? contents
You asked for help about help category: "Contents"
For more information, type ‘help <item>‘, where <item> is one of the following
categories:
Account Management
Administration
Compound Statements
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Help Metadata
Language Structure
Plugins
Procedures
Storage Engines
Table Maintenance
Transactions
User-Defined Functions
Utility
mysql> ? Data Definition
You asked for help about help category: "Data Definition"
For more information, type ‘help <item>‘, where <item> is one of the following
topics:
ALTER DATABASE
ALTER EVENT
ALTER FUNCTION
ALTER LOGFILE GROUP
ALTER PROCEDURE
ALTER SERVER
ALTER TABLE
ALTER TABLESPACE
ALTER VIEW
CONSTRAINT
CREATE DATABASE
CREATE EVENT
CREATE FUNCTION
CREATE INDEX
CREATE LOGFILE GROUP
CREATE PROCEDURE
CREATE SERVER
CREATE TABLE
CREATE TABLESPACE
CREATE TRIGGER
CREATE VIEW
DROP DATABASE
DROP EVENT
DROP FUNCTION
DROP INDEX
DROP PROCEDURE
DROP SERVER
DROP TABLE
DROP TABLESPACE
DROP TRIGGER
DROP VIEW
RENAME TABLE
TRUNCATE TABLE
mysql> ? CREATE DATABASE
Name: ‘CREATE DATABASE‘
Description:
Syntax:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification] ...
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
CREATE DATABASE creates a database with the given name. To use this
statement, you need the CREATE privilege for the database. CREATE
SCHEMA is a synonym for CREATE DATABASE.
URL: http://dev.mysql.com/doc/refman/5.6/en/create-database.html
mysql>
三.数据库的操作
1.创建数据库
mysql> create database db_bank; Query OK, 1 row affected (0.00 sec)
也可以创建时指定字符集
mysql> create database db_shop default charset=utf8; Query OK, 1 row affected (0.00 sec)
2.查看数据库
查看所有的数据库
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bank | | db_bank | | db_itheima | | db_shop | | mysql | | performance_schema | | test | +--------------------+ 8 rows in set (0.00 sec)
查看指定的数据库
mysql> show create database db_shop; +----------+------------------------------------------------------------------+ | Database | Create Database | +----------+------------------------------------------------------------------+ | db_shop | CREATE DATABASE `db_shop` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+------------------------------------------------------------------+ 1 row in set (0.00 sec)
3.修改数据库
mysql5之后就不能修改数据库名称了,需要先删除再重新创建
可以修改数据库的字符集
mysql> alter database db_shop default charset utf8mb4; Query OK, 1 row affected (0.00 sec) mysql> show create database db_shop; +----------+---------------------------------------------------------------------+ | Database | Create Database | +----------+---------------------------------------------------------------------+ | db_shop | CREATE DATABASE `db_shop` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ | +----------+---------------------------------------------------------------------+ 1 row in set (0.00 sec)
4.删除数据库
mysql> drop database db_shop; Query OK, 0 rows affected (0.00 sec) mysql> show database db_shop; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘database db_shop‘ at line 1 mysql>
以上是关于mysql概述及基本语法的主要内容,如果未能解决你的问题,请参考以下文章
Linux——Linux驱动之设备树基本概述及语法总结(为什么会出现设备树,设备树解决了什么问题?)