77范文网 - 专业文章范例文档资料分享平台

mysql命令大全(3)

来源:网络收集 时间:2019-05-27 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

--all-databases, -A

Dump all tables in all databases. This is the same as using the --databases option and naming all the databases on the command line.

--databases, -B

Dump several databases. Normally, mysqldump treats the first name argument on the command line as a database name

and following names as table names. With this option, it treats all name arguments as database names.

CREATE DATABASE IF NOT EXISTS db_name and USE db_name statements are included in the output before each new database.

--host=host_name, -h host_name

Dump data from the MySQL server on the given host. The default host is localhost. --opt

This option is shorthand; it is the same as specifying --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset.

It should give you a fast dump operation and produce a dump file that can be reloaded into a MySQL server quickly.

In MySQL 5.0, --opt is on by default, but can be disabled with --skip-opt.

To disable only certain of the options enabled by --opt, use their --skip forms;

for example, --skip-add-drop-table or --skip-quick. 还有一些其他参数,有兴趣可以学习 2.6. 表数据备份 mysql>use test;

mysql> CREATE TABLE imptest(id INT, n VARCHAR(30)); Query OK, 0 rows affected (0.03 sec)

方法一:

导出使用:Mysqldump

E:\\mysql>mysqldump -uptsdb -pptsdb -where \test imptest

E:\\mysql>mysqldump -uptsdb -pptsdb imptest>e:\\mysql\\imp\\imptest2.txt 导入使用 mysql

mysql -uptsdb -pptsdb< imptest2.txt

方法二:

导出使用 select into OUTFILE

mysql> select * from imptest where id=101 into OUTFILE 'e:\\\\mysql\\\\imp\\\\test3.txt' FIELDS TERMINATED BY ',';

test

导入使用 LOAD DATA INFILE

LOAD DATA [LOW_PRIORITY | CONCURRENT] 'file_name.txt' [REPLACE | IGNORE] INTO TABLE tbl_name [FIELDS

[TERMINATED BY 'string']

[[OPTIONALLY] ENCLOSED BY 'char'] [ESCAPED BY 'char' ] ]

[LINES

[STARTING BY 'string'] [TERMINATED BY 'string'] ]

[IGNORE number LINES]

[(col_name_or_user_var,...)] [SET col_name = expr,...]]

[LOCAL]

INFILE

例子:

mysql> LOAD DATA INFILE 'e:\\\\mysql\\\\imp\\\\test3.txt' INTO TABLE imptest FIELDS TERMINATED BY ',';

导入使用mysqlimport: E:\\mysql>mysqlimport -uptsdb -pptsdb --local test E:\\mysql\\imp\\imp.txt

mysqlimport: Error: Table 'test.imp' doesn't exist, when using table: imp

E:\\mysql>mysqlimport -uptsdb -pptsdb --local test E:\\mysql\\imp\\imptest.txt

test.imptest: Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 注意:文件名必须跟表名相同 参数

-d or --delete 新数据导入数据表中之前删除数据数据表中的所有信息 -f or --force 不管是否遇到错误,mysqlimport将强制继续插入数据 -i or --ignore mysqlimport跳过或者忽略那些有相同唯一 -r or -replace 这个选项与-i选项的作用相反;此选项将替代 表中有相同唯一关键字的记录

2.7. 数据管道导入导出 E:\\mysql>mysql -h10.5.1.66 -uroot -proot --default-character-set=name frontdb_20060415(databasename) >e:/mysql/test.txt (输出的sql 语句)

1:>;create databases newname(在新的server上建立空的数据库)

2:#/usr/local/mysql/bin/mysqldump databasename >*.sql(在旧的服务器上导出数据库)

3:#/usr/local/mysql/bin/mysql databasename < *.sql(在新的服务器上导入*.sql)

注意数据库名要一一对应. 2.8. 各种字段的取值范围 TINYINT 1 byte -128 - 127

TINYINT UNSIGNED 1 byte 0 ? 255 即0-(28-1) SMALLINT 2 bytes

-32768 - 32767 即-215至(215-1) SMALLINT UNSIGNED 2 bytes 0 - 65535 即0至(216-1) MEDIUMINT 3 bytes

-8388608 - 8388607 即?223至(223-1) MEDIUMINT UNSIGNED 3 bytes

0 - 16777215 即0至(224-1) INT 或 INTEGER 4 bytes

-2147483648 - 2147483647 即?231至(231-1) INT UNSIGNED 或 INTEGER UNSIGNED 4 bytes 0 - 4294967295 即0至(232-1) BIGINT 8 bytes

-9223372036854775808 - 9223372036854775807 即?263至(263-1) BIGINT UNSIGNED 8 bytes

0 - 18446744073709551615 即0至(264-1) FLOAT 4 bytes

-3.402823466E+38 - -1.175494351E-38 0

1.175494351E-38 - 3.402823466E+38

DOUBLE 或 DOUBLE PRECISION 或 REAL 8 bytes

-1.7976931348623157E+308 - -2.2250738585072014E-308 0

2.2250738585072014E-308 - 1.7976931348623157E+308

DECIMAL[(M,[D])] 或 NUMERIC(M,D) 不定

由M(整个数字的长度,包括小数点,小数点左边的位数,小数点右边的位数,但不包括负号)和

D(小数点右边的位数)来决定,M缺省为10,D缺省为0 DATE 3 bytes

1000-01-01 - 9999-12-31 DATETIME 8 bytes

1000-01-01 00:00:00 - 9999-12-31 23:59:59 TIMESTAMP 4 bytes

1970-01-01 00:00:00 - 2037-12-31 23:59:59

TIME 3 bytes

-838:59:59' to 838:59:59 YEAR[(2|4)] 1 byte

缺省为4位格式,4位格式取值范围为1901 - 2155,0000,2位格式取值范围为70-69(1970-2069)

CHAR(M) [BINARY] 或 NCHAR(M) [BINARY] M bytes

M的范围为1 - 255,如果没有BINARY项,则不分大小写,NCHAR表示使用缺省的字符集.在数据库 中以空格补足,但在取出来时末尾的空格将被去掉. [NATIONAL] VARCHAR(M) [BINARY]

Before 5.0.3 M的范围为0?255 L+1 bytes L<=M 5.0.3 以及以后 M 范围为 0-65535 L+1 bytes L<=M 0<=M<=256 L+2 bytes L<=M 256<=65535

在数据库中末尾的空格将自动去掉.

TINYBLOB 或 TINYTEXT L+1 bytes 255(2^8-1)个字符

BLOB 或 TEXT L+2 bytes 65535(2^16-1)个字符

MEDIUMBLOB 或 MEDIUMTEXT L+3 bytes 16777215 (2^24-1)个字符

LONGBLOB 或 LONGTEXT L+4 bytes 4294967295 (2^32-1)个字符

ENUM('value1','value2',...) 1 or 2 bytes 可以总共有65535个不同的值

SET('value1','value2',...) 1/2/3/4/8 bytes 最多有64个成员 2.9. 查询

2.9.1. limit

LIMIT子句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两个参数,如果给出两个参数,

第一个参数指定返回的第一行在所有数据中的位置,从0开始(注意不是1),第二个参数指定最多返回行 数。例如:

select * from table LIMIT 5,10; #返回第6-15行数据 select * from table LIMIT 5; #返回前5行 select * from table LIMIT 0,5; #返回前5行 2.9.2. join 详解

还是先 Create table 吧

create table emp(

id int not null primary key, name varchar(10) );

create table emp_dept(

dept_id varchar(4) not null, emp_id int not null, emp_name varchar(10),

primary key (dept_id,emp_id));

insert into emp() values (1,\(2,\(3,\(4,\(5,\(6,\(7,\(8,\(9,\(10,\

insert into emp_dept() values (\(\(\(\(\(\>> left join -------------

select a.id,a.name,b.dept_id

from emp a left join emp_dept b on (a.id=b.emp_id);

# 挑出左边的 table emp 中的所有资料,即使 emp_dept 中没有的资料也挑出来,没有的就用 NULL 来显示,

# 也即显示资料是以左边的 table emp 中的资料为基础

mysql> select a.id,a.name,b.dept_id

-> from emp a left join emp_dept b on (a.id=b.emp_id); +----+-----------+---------+ | id | name | dept_id |

+----+-----------+---------+ | 1 | Dennis-1 | R&D | | 2 | Dennis-2 | DEv | | 3 | Dennis-3 | R&D | | 4 | Dennis-4 | Test | | 5 | Dennis-5 | Test |

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库mysql命令大全(3)在线全文阅读。

mysql命令大全(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/642631.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: