数据库学习笔记-20170309

news/2024/7/9 1:00:03 标签: 数据库, 运维

数据库语言:

DDL(Data Defination Language):

数据定义语言,主要用于定义数据库、表、视图、索引和触发器等。像DROP/CREATE/ALTER.


DML(Data Manipulation Language):

主要包括对数据的增删改查。INSERT插入数据、UPDATE更新数据、DELETE删除数据。


DQL(Data Query Language):

数据检索语句,用来从表中获取数据,确定数据怎么在应用程序中给出。像SELECT查询语句。


DCL(Data Control Language):

数据控制语言,主要用于控制用户访问的权限。像GRANT/REVOKE/COMMIT/ROLLBACK等语句。



--prompt 修改msql命令提示符,只对当前登录有效。


mysql --prompt meng

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


meng

meng

meng

mengshow schemas;


退出:(三选一都行)

\q

quit

exit



mysql>select version();  #查看当前版本


mysql>select user(); #查看当前的用户

+----------------+

| user()         |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec)



mysql>select now();  #查看当前的时间

+---------------------+

| now()               |

+---------------------+

| 2017-03-07 22:05:43 |

+---------------------+

1 row in set (0.01 sec)



mysql语句规范:

1、关键字与函数名称全部大写;

2、数据库名称、表字段、字段名称等全部小写;

3、sql语句必须以分隔符结尾。

4、sql语句支持折行操作,只要不把单词、标记或者引号字符串分割为2部分。可以在下一行继续写。

5、数据库名称、表名称、字段名称等尽量不要使用mysql的保留字,如果需要使用的时候使用梵音好(``)将名称括起来。


\c #此命令不执行

mysql> select now()\c



delimiter (\d) Set statement delimiter.  #修改默认的分隔符,只对当前登录有效。

mysql> delimiter //

mysql> select now();

    -> //

+---------------------+

| now()               |

+---------------------+

| 2017-03-07 22:29:19 |

+---------------------+

1 row in set (0.00 sec)


mysql> select now()//

+---------------------+

| now()               |

+---------------------+

| 2017-03-07 22:29:29 |

+---------------------+

1 row in set (0.00 sec)


mysql> \q

Bye




#命令提示符修改

\h 主机

\D 日期

\d 数据库

\u 用户

mysql> prompt \h~\D~\d

PROMPT set to '\h~\D~\d'

localhost~Wed Mar  8 03:31:43 2017~(none)use zabbix

Database changed

localhost~Wed Mar  8 03:31:52 2017~zabbixshow tables;

Empty set (0.00 sec)


localhost~Wed Mar  8 03:32:01 2017~zabbix



数据库中引号:(引号需要成对出现,sql语句支持折叠)

mysql>select

    -> 

    -> now()'

    '> ';

+---------------------+

|                     |

+---------------------+

| 2017-03-08 03:53:24 |

+---------------------+

1 row in set, 1 warning (0.00 sec)


mysql>


#操作日志输出

mysql>\T /data/www/

mysql: Can't create/write to file '/data/www/' (Errcode: 21 - Is a directory)

Error logging to file '/data/www/'

mysql>\T /data/www/mysql1.txt

Logging to file '/data/www/mysql1.txt'

mysql>select now();

+---------------------+

| now()               |

+---------------------+

| 2017-03-08 04:04:48 |

+---------------------+

1 row in set (0.00 sec)


mysql>\t #结束操作日志输出

Outfile disabled.

mysql>\q

Bye

[root@localhost ~]# cat /data/www/mysql1.txt 

mysql>select now();

+---------------------+

| now()               |

+---------------------+

| 2017-03-08 04:04:48 |

+---------------------+

1 row in set (0.00 sec)


mysql>\t

[root@localhost ~]# 


#\w关闭警告 \W 开启警告

mysql> \w

Show warnings disabled.

mysql> \W

Show warnings enabled.

mysql> show warnings;

+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+

| Level | Code | Message                                                                                                                                                   |

+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+

| Error | 1064 | 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 'warings' at line 1 |

+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)




#创建数据库,如果不存在则创建。

mysql> create schema if not exists test;

Query OK, 1 row affected, 1 warning (0.00 sec)


Note (Code 1007): Can't create database 'test'; database exists

mysql> 



#查看数据库的定义:

mysql> show create schema test2;

+----------+------------------------------------------------------------------+

| Database | Create Database                                                  |

+----------+------------------------------------------------------------------+

| test2    | CREATE DATABASE `test2` /*!40100 DEFAULT CHARACTER SET latin1 */ |

+----------+------------------------------------------------------------------+

1 row in set (0.00 sec)




#修改指定数据库字符集编码:

mysql> alter schema test2 default character set utf8;

Query OK, 1 row affected (0.00 sec)


mysql> alter schema test2 default character set gbk;

Query OK, 1 row affected (0.00 sec)



#查看指定数据库创建信息:

mysql> show create schema test2;

+----------+---------------------------------------------------------------+

| Database | Create Database                                               |

+----------+---------------------------------------------------------------+

| test2    | CREATE DATABASE `test2` /*!40100 DEFAULT CHARACTER SET gbk */ |

+----------+---------------------------------------------------------------+

1 row in set (0.00 sec)



#查看当前所在的数据库

mysql> select  database();

+------------+

| database() |

+------------+

| test       |

+------------+

1 row in set (0.00 sec)


mysql> status;

--------------

mysql  Ver 14.14 Distrib 5.6.29, for linux-glibc2.5 (x86_64) using  EditLine wrapper


Connection id: 13

Current database: test

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.6.29 MySQL Community Server (GPL)

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: latin1

Db     characterset: latin1

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /tmp/mysql.sock

Uptime: 1 day 7 hours 40 min 4 sec


Threads: 1  Questions: 107  Slow queries: 0  Opens: 67  Flush tables: 1  Open tables: 60  Queries per second avg: 0.000

--------------


#删除指定数据库

mysql> drop schema test2;

Query OK, 0 rows affected (0.03 sec)


mysql> show schemas;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

| zabbix             |

+--------------------+

5 rows in set (0.00 sec)





http://www.niftyadmin.cn/n/1748388.html

相关文章

container_of

container_of 理解 收藏 问题:如何通过结构中的某个变量获取结构本身的指针??? 关于container_of见kernel.h中:/*** container_of - cast a member of a structure out to the containing structure* ptr: the pointer to t…

android SoundPool

SoundPool主要用于播放时间较短的音效,使用soundPool占用的资源也不会太大。 参考链接 http://o7planning.org/en/10523/playing-sound-effects-in-android-with-soundpool http://www.cnblogs.com/plokmju/p/android_SoundPool.html Example 创建一个按键&#xff…

嵌入式系统终端分析

嵌入式系统终端分析 ------------------------------------本文系本站原创,欢迎转载! 转载请注明出处:http://sjj0412.cublog.cn/------------------------------------------ 当我们打开机器或一个嵌入式系统时,我们可能都适应了它会显示信息,我们也…

什么是 jQuery EasyUI

jQuery EasyUI 是一个基于 jQuery 的框架,集成了各种用户界面插件。 jQuery EasyUI 框架提供了创建网页所需的一切,帮助您轻松建立站点。 easyui 是一个基于 jQuery 的框架,集成了各种用户界面插件。easyui 提供建立现代化的具有交互性的 jav…

嵌入式 linux 智能设备应用中 web 支持的实现(一)

嵌入式 linux 智能设备应用中 web 支持的实现(一)由两篇文章组成的系列文章主要阐述如何在嵌入式 Linux 智能设备的应用程序中增加 Web 支持。第 1 部分,我们将会介绍嵌入式 Linux 智能设备开发的现状、Qt 和 WebKit 的概念。并以广告机和手持点菜机等应用为例&…

嵌入式 linux 智能设备应用中 web 支持的实现(二)

嵌入式 linux 智能设备应用中 web 支持的实现(二)由两篇文章组成的系列文章主要阐述如何在嵌入式 Linux 智能设备的应用程序中增加 Web 支持。第 1 部分介绍了如何设备上提供常规 Web 功能的支持。本文是第2部分,将重点介绍如何让在嵌入式设备上运行的 Web 程序能支…

使用LCP建立链路

2.3.5 使用LCP建立链路LCP操作包括链路建立、链路维护和链路终止。1.LCP操作LCP使用3种LCP帧来完成每个LCP阶段的工作。链路建立帧(Configure-Request、Configure-Ack、Configure-Nak和Configure-Reject)用于建立和配置链路。链路维护帧&…

使用DirecetFB支持Qt4.7.0,加速启动QT

使用DirecetFB支持Qt4.7.0 使用DirecetFB支持Qt4.7.0摘要:如何在ok6410上使用Directfb,并且使用它支持Qt4.7.0关键字:directfb 1.2.8 Qt4.7.0 tslib ok64101.前言:很久之前就已经听说过directFb,但实际上…