首页 » MySQL » MySQL常用脚本

MySQL常用脚本

2017-01-07 15:10:14阅读(203)

常用脚本

登录 : MySQL -u root -p

退出: exit

添加用户:

use mysql;
INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'guest', PASSWORD('guest123'), 'Y', 'Y', 'Y');
FLUSH PRIVILEGES;

数据库操作:

use 数据库名;
show databases;
show tables;
show columns from 数据库;

创建数据库:

 mysqladmin -u root -p create 数据库

删除数据库:

 mysqladmin -u root -p drop 数据库;

数据类型:

数:

TINYINT,SMALLINT,MEDIUMINT,INT,BIGINT,FLOAT,DOUBLE,DECIMAL

日期时间:

DATE(yyyy-mm-dd),TIME(hh-mm-ss),YEAR,DATETIME,TIMESTAMP

字符:

CHAR,VARCHAR,TINYBLOB,TINYTEXT,BLOB,TEXT.MEDIUMBLOB,MEDIUMTEXT,LONGBLOB,LONGTEXT

操作:

CREATE TABLE xxx (col type, col type);
CREATE TABLE insect 
( 
id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
PRIMARY KEY (id),
name VARCHAR(30) NOT NULL, # type of insect 
date DATE NOT NULL, # date collected 
origin VARCHAR(30) NOT NULL # where collected
);
DROP/DELETE TABLE xxx;
INSERT INTO xxx (xx,xx) VALUES (xx,xx);
SELECT xx FROM xx;
UPDATE xxx SET xx=xx;

导入导出:

SELECT * FROM xx INTO OUTFILE 'data.txt' FIELD TERMINATED BY ','  OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
LOAD DATA LOCAL INFILE 'dump.txt' INTO TABLE mytbl FIELDS TERMINATED BY ':' LINES TERMINATED BY '\r\n';

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹