MySQL Commands

1. create database yyzc; show database yyzc;z drop database yyzc;
2. show engines; show variables like ‘have %‘; Alter table user engine=myisam
3. mysql -h localhost -u root -p; enter passwork
4. 创建、修改和删除表

创建表

1). create table example_0(id int,name varchar(20),sex boolean);

2). create table example_1 (stu_id int primary key, stu_name varchar(20),stu_sex boolean);

3). create table example_2 (stu_id int,course_id int grade float,primary key(stu_id, course_id));

4). create table example_3 (id int primary key, stu_id int course_id int, Constraint c_fk foreign key(stu_id,course_id) references example_2(stu_id,course_id));

5). create table example_4 (id int not null primary key, name varchar(20) not null, stu_id int, Constraint d_fk foreign key(stu_id) references example_1(stu_id) );

6). create table example_5(id int primary key, stu_id int unique, name varchar(20) not null);

7). create table example_6(id int primary key, Auto_increment, stu_id int unique, name varchar(20) not null);

8). create table example_7(id int primary key, Auto_increment, stu_id int unique, name varchar(20) not null English varchar(20) default ‘zero‘, Math float default 0, Computer Float default 0); desc user show create table user

修改字段

1). alter table example rename user

2). alter table example modify name varchar(20)

3). alter table example change stu_name name varchar(20)

4). alter table example change stu_sex sex int(2)

增加字段

5). alter table user add phone varchar(20)

6). alter table user add age int(4) not null

7). alter table user add num int(4) primary key first

8). alter table user add address varchar(40) not null after phone

删除字段

9). alter table user drop id

10). alter table user modify name varchar(20) first

11). alter table user modify sex tinyint(1) after age

删除表外键约束

alter table example drop foregin key c_fk
删除表

1). dorp table example

2). alter table example drop foreign key d_fk, drop table example

时间: 2024-08-09 19:52:27

MySQL Commands的相关文章

使用otl,报错:mysql Commands out of sync; you can't run this command now

1.代码如下: void TestCache(otl_connect& otlConn) { try { char sql[1024] = {0}; sprintf(sql,"call test1(1)"); otl_stream stream(100, sql, otlConn,otl_implicit_select); int id; while(!stream.eof()) { stream>>id; char sql2[1024] = {0}; sprint

MySql: ”Commands out of sync“Error (Connect/C++)

使用 Connector/C++ 查询 Mysql , 连续调用存储过程时 会出现如下: Commands out of sync; you can't run this command now,state:HY000 出现原因可以看这里:http://stackoverflow.com/questions/17115919/mysql-commands-out-of-sync-error-c-connector 这一句: Because CALL can return multiple res

How to Install MySQL on CentOS 7

How to Install MySQL on CentOS 7 Updated Thursday, August 27th, 2015 by Linode Use promo code DOCS10 for $10 credit on a new account. Try this Guide Contribute on GitHub View Project | View File | Edit File MySQL is a popular database management syst

【原创】MySQL和PostgreSQL 导入数据对比

在虚拟机上测评了下MySQL 和 PostgreSQL 的各种LOAD FILE方式以及时间. 因为是虚拟机上的测评,所以时间只做参考,不要太较真, 看看就好了. MySQL 工具: 1. 自带mysqlimport工具. 2. 命令行 load data infile ... 3. 利用mysql-connector-python Driver来写的脚本. PostgreSQL 工具: 1. pgloader 第三方工具. 2. 命令行 copy ... from ... 3. 利用psyco

MySQL初识

数据库(DataBase):是指长期保存在计算机的存储设备上,按照一定规则组织起来,可以被各种用户或应用共享的数据集合: DBMS:数据库操作系统:一种操作和管理数据库的大型软件,用于建立.使用和维护数据库,对数据库进行统一管理和控制,以保证数据库的安全性和完整性: DDL:定义语言 DML:操作语言 DCL:控制语言 MYSQL 由三个瑞典人于20世纪90年代开发的一个关系型数据库 MY是创始人之一MICHAEL WIDENIUS女儿MY的名字 常用的数据库:Oracle , DB2 , SQ

如何获取mysql帮助信息

在开发或测试环境在碰到mysql相关故障时,大多数朋友可能会通过论坛发帖,QQ群讨论方式来获取帮助.该方式是获取帮助的有效途径之一.然而如果在生产环境,在没有网络的环境下,这些方式就无助于问题的解决.无论何种数据库,从官方网站获取帮助是最直接最有效的方式.其次没有网络的环境下,我们可以通过MySQL客户端工具自带的帮助信息来解决问题. 1)MySQL官方手册    和Oracle官方文档一下,MySQL官方手册是获取MySQL帮助最直接最效的方式.该手册包含很多个部分,比如有关SQL的语法,My

MySQL和PostgreSQL 导入数据对照

在虚拟机上測评了下MySQL 和 PostgreSQL 的各种LOAD FILE方式以及时间. 由于是虚拟机上的測评,所以时间仅仅做參考,不要太较真, 看看就好了.MySQL 工具:    1. 自带mysqlimport工具.    2. 命令行 load data infile ...    3. 利用mysql-connector-python Driver来写的脚本. PostgreSQL 工具:    1. pgloader 第三方工具.    2. 命令行 copy ... from

Ubuntu12.04 以通用可执行文件(Generic Binaries)安装MySQL

选择安装版本: [http://dev.mysql.com/doc/refman/5.6/en/choosing-version.html] Normally, if you are beginning to use MySQL for the first time or trying to port it to some system for which there is no binary distribution, use the most recent General Availabil

MySQL应用管理常用命令

登录mysqlmysql -urot -p  单实例 mysql -uroot -p -S /data/3306/mysql.sock  多实例MySQL帮助命令helpmysql> helpFor information about MySQL products and services, visit:   http://www.mysql.com/For developer information, including the MySQL Reference Manual, visit: