MySQL-SQL语法基础

一、客户端命令

1.1、mysql命令

-u  -p  -S  -h  -P  -e 
mysql -uroot -p -e "show status"

1.2、接受用户命令

help 
\G 
ctrl+c  #5.7 以上版本,结束上条命令运行,类似linux 
ctrl+d  \q   exit quit
use  
source	source /root/world.sql

系统相关命令:

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement. 
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.	#存储过程及函数
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

二、SQL分类

SQL: 结构化查询语言(Structured Query Language)

DDL : 数据定义语言(Data define Language)
DCL : 数据控制语言(Data Control Language)
DML : 数据操作语言(Data Manipulation Language)
DQL : 数据查询语言(Data QueryLanguage)

三、DDL:数据定义语言

3.1、create database语句

image

3.1.1、示例

CREATE DATABSE wordpress CHARSET  utf8;	#可以指定字符集及排序规则

3.1.2、开发规范

(1)  库名字必须小写,不能有数字开头,不要超过16个字符 *****
(2)  库名必须和业务有关
(3)  建库时必须添加字符集
(4)  生产中禁止DROP命令
(5)  做变更类操作,需要提前备份

3.2、drop database语句(危险)

3.3、alter database语句

3.3.1、示例

#例如:更改库的字符集(utf8 ----> utf8mb4)
alter database abc charset utf8mb4;
alter database abc character set utf8mb4;

3.4、create table语句

image

猜你喜欢

转载自www.cnblogs.com/hujinzhong/p/11626557.html
今日推荐