web架构之mysql服务器

SQL概述
结构化查询语言(Structured Query Language)简称SQL,是一种特殊目的的编程语言,是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。
从上可以看出我们数据库相关工作职位大概两种:DBD和DBA
dba是数据库管理员database administrator
dbd是数据库开发人员database developer
SQL 是1986年10 月由美国国家标准局(ANSI)通过的数据库语言美国标准,接着,国际标准化组织(ISO)颁布了SQL正式国际标准。1989年4月,ISO提出了具有完整性特征的SQL89标准,1992年11月又公布了SQL92标准,在此标准中,把数据库分为三个级别:基本集、标准集和完全集。
SQL语句结构
结构化查询语言包含6个部分
数据查询语言(DQL)
其语句,也称为“数据检索语句”,就是从表中查询数据。
数据操作语言(DML):
在表中添加,修改和删除数据记录。也称为动作查询语言。
事务处理语言(TPL):
它由多条sql语句组成的整体,它的语句能确保被DML语句修改的表中的所有记录及时得到更新。
数据控制语言(DCL):
设置数据库的访问权限。
数据定义语言(DDL):
在数据库中创建表或删除表(CREAT TABLE 或 DROP TABLE);为表加入索引等。
指针控制语言(CCL):
它的语句,像DECLARE CURSOR,FETCH INTO和UPDATE WHERE CURRENT用于对一个或多个表单独行的操作。

登录mysql -uroot -p(登录密码)

进入数据库中查看

1:information_schema这个数据库保存了MySQL服务器所有数据库的信息。如数据库名,数据库的表,表栏的数据类型,访问权限等。 [ˈskimə]元数据
2:performance_schema 这是MySQL5.5新增的一个性能优化的引擎:命名PERFORMANCE_SCHEMA,主要用于收集数据库服务器性能参数。MySQL用户是不能创建存储引擎为PERFORMANCE_SCHEMA的表
http://www.cnblogs.com/hzhida/archive/2012/08/08/2628833.html
3:mysql库是系统库,里面保存有账户信息,权限信息等。
4:mysql5.7增加了sys 系统数据库,通过这个库可以快速的了解系统的元数据信息,元数据是关于数据信息的数据,如数据库名或表名,列的数据类型,或访问权限等。
Show databases;\G 以行的方式显示

mysql -e后面直接跟sql语句,这种方式一般是在shell脚本中用到
[root@cong11 ~]# mysql -e 'show databases' -uroot -p123456(交互式)

创建数据库
语法
create database 数据库名;
创建数据库注意事项
1、在文件系统中,MySQL的数据存储区以目录方式表示MySQL数据库。因此,上面命令中的数据库名字必须与操作系统的约束的目录名字一致。例如不允许文件和目录名中有\,/,:,*,?,”,<,>,|这些符号,在MySQL数据库名字中这些字母会被自动删除。
[root@cong11 ~]# ls /data/mysql/data/
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 ibtmp1 mysql performance_schema sys
2、遵从目录的约束
3、数据库的名字不能超过64个字符,包含特殊字符的名字或者是全部由数字或保留字组成的名字必须用反引号`包起来。<br/>4、数据库不能重名<br/>创建数据库 creat databaesemmi`;

选择要操作的数据库
我们需要使用哪个数据库,就用use进行选择,后面的操作默认都是在被选择的数据库中进行操作。
选择需要操作的数据库
Use db1
查看当前所在位置select database();

选择默认的数据库

删除数据库 drop database 选择需要删除的数据库

查看表结构

查看表执行了那些命令 show create table (表名)\G以行显示

删除表show tables;

创建表create table HA(id int (11),name char(20),age int);
Creat table 表名(字段名,类型,字段名,类型,字段名,类型);

修改表中的字段类型和字段名称 进入指定库use(库名);查看表结构desc(表名);

修改表名称alter table(表名)renmae (新表名)

修改表中的字段类型和字段名称

修改表中的字段类型 alter table(表名)modify 手机号 int (字段类型)

修改表中的字段类型和字段名称alter table (表名)change id (字段名称)char(11)

在表中添加字段alter table 表名 add 字段名 字段类型enum(‘W’,’M’)

转载于:https://blog.51cto.com/13968682/2399805

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL Server 5.1 This is a release of MySQL, a dual-license SQL database server. For the avoidance of doubt, this particular copy of the software is released under the version 2 of the GNU General Public License. MySQL is brought to you by Oracle. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. License information can be found in the COPYING file. MySQL FOSS License Exception We want free and open source software applications under certain licenses to be able to use specified GPL-licensed MySQL client libraries despite the fact that not all such FOSS licenses are compatible with version 2 of the GNU General Public License. Therefore there are special exceptions to the terms and conditions of the GPLv2 as applied to these client libraries, which are identified and described in more detail in the FOSS License Exception at <http://www.mysql.com/about/legal/licensing/foss-exception.html>. This distribution may include materials developed by third parties. For license and attribution notices for these materials, please refer to the documentation that accompanies this distribution (see the "Licenses for Third-Party Components" appendix) or view the online documentation at <http://dev.mysql.com/doc/>. GPLv2 Disclaimer For the avoidance of doubt, except that if any license choice other than GPL or LGPL is available it will apply instead, Oracle elects to use only the General Public License version 2 (GPLv2) at this time for any software where a choice of GPL license versions is made available with the language indicating that GPLv2 or any later version may be used, or where a choice of which version of the GPL is applied is otherwise unspecified. For further information about MySQL or additional documentation, see: - The latest information about MySQL: http://www.mysql.com - The current MySQL documentation: http://dev.mysql.com/doc Some Reference Manual sections of special interest: - If you are migrating from an older version of MySQL, please read the "Upgrading from..." section. - To see what MySQL can do, take a look at the features section. - For installation instructions, see the Installing and Upgrading chapter. - For the new features/bugfix history, see the MySQL Change History appendix. You can browse the MySQL Reference Manual online or download it in any of several formats at the URL given earlier in this file. Source distributions include a local copy of the manual in the Docs directory.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值