mysql 数据库复制表 create table city1 like city;
create table test2 select * from test where 1=2
-- 只复制表结构 create table city1 like city;
INSERT INTO test2 SELECT * FROM test;
-- 上面的表必须存在 -- 复制整张表的数据
create table test2 select * from test -- create database xxx charset
-- create table xxx (id int,xxxxxx)
-- drop table
-- drop database
-- alter table add/drop/modify/change
-- create user
-- drop user select id,name from test limit 1,3; --- 显示第一行之后的三行
用户管理 ---- 定义 : 用户名+主机域 功能:连接数据库、管理数据库对象 连接数据库:
1、定义用户:用户名+主机域, 密码
2、定义权限:对不同的对象进行权限(角色)定义 grant 权限 on 权限范围(对象) to 用户 identified by '';
show grants for oldboy@'10.0.0.%'; 权限(角色):
select
update
delete
insert
drop
create ALL
replication slave 权限范围:
*.* 所有数据库对象
oldboy.* oldboy单库下所有对象
oldboy.test 单表级别 用户:
repl@localhost
repl@'10.0.0.53'
repl@'10.0.0.%'
repl@'10.0.0.5%'
-----
要求:
1、用户只能通过10网段访问,用户名为oldboy,密码为123
2、只能对oldboy数据库下的对象进行增insert create、改update、查select grant select,insert,update,create on oldboy.* to oldboy@'10.0.0.%' identified by ''; drop user oldboy@'10.0.0.%' ----------------
skip-grant-tables 启动过程中跳过授权表。 /application/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking & 在这中模式启动情况下: 无密码登录
网络用户无法登陆
只能本地登录 和授权有关的命令都不能执行了
grant
revoke
drop user
create user use mysql
update user set password=PASSWORD('') where user='sys' and host='localhost'
flush privileges; 5.7 无password 需要修改:authentication_string
use mysql
update user set authentication_string=PASSWORD('') where user='sys' and host='localhost'
flush privileges;
----------------- SQL 是用户用来管理、控制数据库的专用语言 SQL入门 mysql
1、mysql客户端接口自带功能
1、\h 或 help 或 ? 获取帮助
2、\G 格式化输出(行转列)
3、\T 或 tee 记录操作日志 tee /tmp/mysql.log
4、\c 或 CTRL+c 退出mysql
5、\s 或 status 查看数据库状态信息
6、\. 或 source mysql> source /tmp/world.sql
7、\u 或use use world
show databases 看当前所有数据库的名字
show tables 查看当前use到的数据库所有的表
show tables from world 查看目标数据库下的表
8、快捷键
上下翻页
TAB
ctrl +C
ctrl +L 2、SQL
DDL:
数据定义语言
定义范围:
库 :名字、特性
表:表名字、列
DDL语句:
create database oldboy
create table test (id int) 创建库:
CREATE DATABASE db_name CHARACTER SET charset_name COLLATE collation_name
例子
mysql> create database oldboy charset utf8 ;
mysql> show create database oldboy; 查询数据库定义信息。 修改库:
ALTER DATABASE [db_name] CHARACTER SET charset_name COLLATE collation_name
例子:
mysql> alter database oldboy charset gbk; 删除库:
drop database oldboy; show character set;#找字符集和校对规则. 表定义(列):
表名
列名
列属性(数据类型、列约束) 创建表:
create table test(id int);
create table t1(idcard int ,name char(30),sex char(4));
修改表定义:
修改表名:
rename table t1 to test1;
alter table test1 rename to people;
修改表结构:
alter table people add addr char(40) NOT NULL;
指定添加年龄列到name列后面的位置,示例如下:
alter table people add age int(4) after name;
通过下面的命令在第一列添加qq字段。
alter table test add telnum int first;
同时添加多个列定义:
alter table people add id int first ,add sex char(4) after name ;
删除表结构:
alter table people drop sex;
修改表定义
alter table people modify name char(20);
修改列名:
alter table people change name people_name char(30) ;
---------------------------
总结DDL:
create database xxx charset
create table xxx (id int,xxxxxx)
drop table
drop database
alter table add/drop/modify/change
create user
drop user
----------------------------
DCL:数据库控制语言
grant
revoke
-----------------------
DML:
数据操纵语言:针对数据行的操作 insert语句:
create table oldboy (id int,name varchar(20));
insert into oldboy values(1,'oldboy');
insert into oldboy values(2,'yougboy'),(3,'youggilr');
select * from oldboy;
insert into oldboy(name) values('xiaoming'); INSERT INTO `test` VALUES (1,'oldboy'),(2,'oldgirl'),(3,'inca'),(4,'zuma'),(5,'kaka'); ------------------------------------
create table test like oldboy;
insert into oldboy select * from oldboy; ========================== create table test2 select * from test where 1=2 ------------------------------------
update(一定要有where条件)
update test set name='oldboy1' WHERE id = 1; delete(一定要有where条件)
delete from oldboy where id=1;
INSERT INTO `test` VALUES (1,'oldboy'),(2,'oldgirl'),(3,'inca'),(4,'zuma'),(5,'kaka'); 生产中的伪删除 alter table test add state tinyint(2) not null default 1;
update test set state=1;
正常显示:
select * from test where id=1;
update test set state=0 where name='oldboy';
mysql> select * from test where state=1;
+----+---------+-------+
| id | name | state |
+----+---------+-------+
| 2 | oldgirl | 1 |
| 3 | inca | 1 |
| 4 | zuma | 1 |
| 5 | kaka | 1 | mysql> select * from test;
+----+---------+-------+
| id | name | state |
+----+---------+-------+
| 1 | oldboy | 0 |
| 2 | oldgirl | 1 |
| 3 | inca | 1 |
| 4 | zuma | 1 | --------------------------------
DQL: select from select user,password ,host from mysql.user where user='sys';
select user,password ,host from mysql.user where user like 'sy%'; select * from oldboy.test;
select id,name from oldboy.test;
select id,name from test where id=2;
select id,name from test where name='oldgirl';
select id,name from test where id>2;
select id,name from test where id>2 and id<4;
select id,name from test where id>2 or id<4;
select id,name from test;
select id,name from test order by id asc;
select id,name from test order by id desc;
select id,name from test limit 1,3;
#第一行之后取三行 select database(); select user();
mysql 数据库复制表 create table city1 like city;的更多相关文章
- MySQL 建表语句 create table 中的列定义
MySQL 建表语句 create table 中的列定义: column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value ...
- MySQL复制表-CREATE SELECT
假设存在以下Table: mysql> select * from staff; +----+----------+-------+ | id | name | slary | +----+-- ...
- MySQL中表复制:create table like 与 create table as select
CREATE TABLE A LIKE B 此种方式在将表B复制到A时候会将表B完整的字段结构和索引复制到表A中来. CREATE TABLE A AS SELECT x,x,x,xx FROM B ...
- mysql复制表结构create table as和like的区别
对于MySQL的复制相同表结构方法,有create table as 和create table like 两种,区别是什么呢? create table t2 as select * from t1 ...
- JPA连接Mysql数据库时提示:Table 'jpa.sequence' dosen't exisit
场景 在使用JPA连接Mysql数据库进行数据持久化时提示: Table 'jpa.sequence' dosen't exist 注: 博客主页: https://blog.csdn.net/bad ...
- Mysql数据库远程链接、权限修改、导入导出等基本操作
一.连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.例1:连接到本机上的MYSQL. 首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令mysql -ur ...
- 【第四章】MySQL数据库的基本操作:数据库、表的创建插入查看
MySQL数据库基本操作 创建表 create table 查看表结构 desc table, show create table 表完整性约束 修改表 alter table 复制表 create ...
- Mysql数据库常用操作整理
0.说明 MySQL数据库是一个十分轻便的数据库管理系统,相比大型的数据库管理系统如Oracle,MySQL更拥有轻便.灵活.开发速度快的特色,更适用于中小型数据的存储与架构,被数以万计的网站采用.从 ...
- Mysql数据库基础操作
Mysql数据库基础操作 在mysql数据库中开启使用tab键补全功能 1)修改主配置文件/etc/mysql/my.cnf(mysql和mariadb目录有些不同) vim /etc/mysql/m ...
随机推荐
- HttpClient 处理中文乱码
HttpClient 请求的中文乱码问题 相关类库: commons-codec-1.3.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.ja ...
- JAVA常见算法题(二十五)
/** * Java实现中文数字转换为阿拉伯数字 * * * @author WQ * */ public class Demo26 { public static void main(String[ ...
- android 用 XML 自定义View边框个数,只有一边或两边
<?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android=" ...
- 安装notepad++ in ubuntu16.04
一.安装notepad++ Ubuntu下的安装方法: sudo add-apt-repository ppa:notepadqq-team/notepadqq sudo apt-get update ...
- linux下GPRS模块ppp拨号上网
---------------------------------------------------------------------------------------------------- ...
- POJ 2386 Lake Counting 搜索题解
简单的深度搜索就能够了,看见有人说什么使用并查集,那简直是大算法小用了. 由于能够深搜而不用回溯.故此效率就是O(N*M)了. 技巧就是添加一个标志P,每次搜索到池塘,即有W字母,那么就觉得搜索到一个 ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- c# 用OpenXmL读取.xlsx格式的Excel文件 返回DataTable
1.须要引用的dll : DocumentFormat.OpenXml.dll ---须要安装一下OpenXml再引用 WindowsBase ---直接在项目里加入引用 2.方法: /// & ...
- 实现乐鑫esp8266的无线OTA升级,实现远程在线升级固件
代码地址如下:http://www.demodashi.com/demo/12994.html 一.前言: 写了这么多的8266博文,一直以满意100%的心态去敲写代码固件烧录,以致很少出现 bug ...
- Java中super的几种使用方法并与this的差别
1. 子类的构造函数假设要引用super的话,必须把super放在函数的首位. class Base { Base() { System.out.println("Base" ...