複製資料庫
相同mysql伺服器
create table testbackup select * from test;
相同mysql伺服器,取源表中的某些字段
create table testbackup select field1,field2 from test;
不同mysql伺服器
$mysqldump -u root -p create database test_backup;
$mysqldump -u root -p test > /tmp/testback.sql
$mysql -u root -p test_backup < /tmp/testback.sql
建立歷史表
create temporary table test_tmp select * from test;
常用管理命令
show database;
show tables;
describe tablename;
show columns in tablename;
刪除命令
drop [temporary] table [if exists] tablename [, tablename2,tablename3]
修改表alter table tablename add column colunmname columntype [after columnnamek];
after 可以指定新增的列的位置,不指定則放在最後。
alter table tablename change oldcolumn colunmname columntype
drop table tablename drop columnname;
建立表
型別儲存
查詢速度
指定大小時的含義
最大空間
char
長度固定
快字元數
255 個字元
varchar
長度可變
中5.0.3 之前為位元組,之後為字元
65535 位元組
text
長度可變慢位元組
65535 位元組
$sql
="create table if not exists .``(
`id` bigint(20) not null auto_increment,
`qq` bigint(20) not null,
`type` tinyint (4) not null default '0',
`str` varchar (128) not null default '',
`time` bigint(20) not null default '0',
`date` int(11) not null,
primary key (`id`, `date`),
unique key `qq_str` (`qq`,`str`,`date`),
key `index_type` (`type`) using btree,
key `index_str` (`str`) using btree,
key `index_qq_type` (`qq`, `type`) using btree
) engine = innodb default charset = utf8mb4
partition by range (`date`)
(partition p201910 values less than (201911) engine = innodb"
;
MY SQL 管理資料庫和表
一 建立自定義的資料庫 語法如下 create database if notexists default character set 編碼格式 default collate 排序,分組,比較 建庫語句 建立乙個名為demo的資料庫,編碼為utf 8 create database demo de...
管理MySQL資料庫和表
顯示資料庫 show databases 選擇要使用的資料庫 在使用指定資料庫之前,必須通過使用use語句告訴mysql要使用哪個資料庫。use database name 刪除資料庫 drop database語句 drop database if exists database name 在本教...
MySQL資料庫 資料庫管理
建立使用者,指定明文密碼 create user rose localhost identified by rosepwd 檢視使用者是否建立成功 select user,host from mysql.user 建立使用者,不設定密碼 create user rose01 localhost se...