mysql 操作sql语句 操作数据表
#2. 操作文件
先切换到文件夹下:use db1 查看当前所在的数据库
mysql> select database();
+------------+
| database() |
+------------+
| db1 |
+------------+
1 row in set (0.00 sec)
每创建一个表每个字段都有相应类型
int 整数类型
char 字符类型
增:create table t1(id int,name char); 创建的数据库都在 在 /var/lib/mysql目录下
[root@mysql mysql]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8 [client]
default-character-set=utf8 [mysql]
default-character-set=utf8 [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [root@mysql mysql]# cd /var/lib/mysql
[root@mysql mysql]# ll
总用量 20492
drwx------. 2 mysql mysql 4096 10月 6 03:55 db1
-rw-rw----. 1 mysql mysql 10485760 10月 6 03:49 ibdata1
-rw-rw----. 1 mysql mysql 5242880 10月 6 03:49 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 10月 6 02:16 ib_logfile1
drwx------. 2 mysql mysql 4096 10月 6 02:16 mysql
srwxrwxrwx. 1 mysql mysql 0 10月 6 03:47 mysql.sock
drwx------. 2 mysql mysql 4096 10月 6 02:15 test
db1 数据库下面有 新创建的 t1 数据表
[root@mysql mysql]# cd db1/ [root@mysql db1]# ll
总用量 20
-rw-rw----. 1 mysql mysql 61 10月 6 03:50 db.opt
-rw-rw----. 1 mysql mysql 8586 10月 6 03:55 t1.frm
-rw-rw----. 1 mysql mysql 0 10月 6 03:55 t1.MYD
-rw-rw----. 1 mysql mysql 1024 10月 6 03:55 t1.MYI
查看当前数据库所有表
查:show tables 查表结构 根据数据表名字
show create table t1;
mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`name` char(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
modify 修改意思 只能改字段类型 字段名不能改
改哪个字段
alter table 表名 modify 要改的字段 数据类型 和长度
改:alter table t1 modify name char(3);
mysql> alter table t1 modify name char(3);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`name` char(3) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
另外一种方式查表 查看表结构
desc 表名;
desc t1;
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(3) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
change 可以改字段名 alter table 表名 change 要改的字段 改后的字段 数据类型 和长度
alter table t1 change name name1 char(2);
删:drop table t1;
mysql> alter table t1 change name NAME char(2);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql>
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| NAME | char(2) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`NAME` char(2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
删:drop table t1;
mysql 操作sql语句 操作数据表的更多相关文章
- mysql 操作sql语句 操作数据表中的内容/记录
#3. 操作文件中的内容/记录 往哪张表去插入 insert into 表名指定字段(id,name) 插入要加values(针对前面字段插入)(2,mike); insert into t1(id, ...
- mysql 操作sql语句 目录
mysql 操作sql语句 操作数据库 mysql 操作sql语句 操作数据表 mysql 操作sql语句 操作数据表中的内容/记录
- mysql操作SQL语句
二.数据库操作SQL语句1.显示服务器上当前存在什么数据库SHOW DATABASES; 2.创建名称为rewin的数据库CREATE DATABASE rewin; 3.删除名称为rewin的数据库 ...
- MySQL常用sql语句-----数据表的查询操作
常用的sql语句如下,应对工作足以 1.查询指定字段 select c_id,c_age,c_name from t_student; select c_id as 编号,c_name as 姓名,c ...
- mysql 操作sql语句 操作数据库
sql语句 #1. 操作文件夹 创建数据库:create database db1 charset utf8; 查数据库:show databases; mysql> create databa ...
- MySQL常用sql语句-----数据表的增删改操作
常用sql操作如下: 1.查看当前数据库的所有表 show tables; 2.创建表 create table stu(sid int,sname char(20),sage int default ...
- mysql用sql语句创建表和数据 设置字符编码为utf-8
简而言之 CREATE DATABASE xx CHARACTER SET utf8 COLLATE utf8_general_ci; USE xx; ),qname ) ) ) ) )); ) ,t ...
- MySQL数据库-表操作-SQL语句(一)
1. 数据库操作与存储引擎 1.1 数据库和数据库对象 数据库对象:存储,管理和使用数据的不同结构形式,如:表.视图.存储过程.函数.触发器.事件等. 数据库:存储数据库对象的容器. 数据库分两种 ...
- Mysql常用sql语句(二)- 操作数据表
21篇测试必备的Mysql常用sql语句,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1683347.html ...
随机推荐
- read by other session 等待事件。
今天是2014-01-06,从今天开始,打算春节之前每天学习一个等待事件,今天就记录一下read by other session这个等待事件笔记. 什么是read by other session? ...
- Delphi应用程序的调试(二)使用断点
Delphi应用程序的调试(二)使用断点 使用断点(Using Breakpoints) 当用户从Delphi IDE 运行程序时,程序全速运行,只会在设置了断点的地方停住. New Term 断点( ...
- GDI+ 和GDI
GDI:Graphics Device Interface,即图形设备接口,是Windows API的一个重要组成部分.它是Windows图形显示程序与实际物理设备之间的桥梁,GDI使得用户无需关心具 ...
- win7 开机自启动控制
直接用win+r运行 --- 输入 msconfig 去除“OneNote”开机自启动方法:取消勾选,点击 “应用” ,然后点击“确定” 即可
- LeetCode 38 Count and Say(字符串规律输出)
题目链接:https://leetcode.com/problems/count-and-say/?tab=Description 1—>11—>21—>1211—>111 ...
- sencha touch 可自动增长高度TextArea
js代码如下: /* *高度自动增长的文本框 */ Ext.define('ux.TextArea', { extend: 'Ext.field.TextArea', xtype: 'autoText ...
- sencha touch list css(样式) 详解
/* *自定义列表页面 */ Ext.define('app.view.util.MyList', { alternateClassName: 'myList', extend: 'Ext.List' ...
- [转]Windows上搭建Kafka运行环境
[转]http://www.cnblogs.com/alvingofast/p/kafka_deployment_on_windows.html Windows上搭建Kafka运行环境 完整解决方 ...
- 编译源码 JAVA out of memory
- DependencyProperty属性介绍
1 DependencyProperty从属属性 1. 从属属性要定义为静态.为了在外部可以绑定,最好定义为Public 2. 从属属性实际上是取代了正常属性的存值变量 3. ...