MYSQL常用命令
来源:互联网 发布:mac软件打不开一直在跳 编辑:程序博客网 时间:2024/06/09 18:06
MySQL常用命令
1. 创建数据库
create database name;
2. 选择数据库
use databasename;
3. 删除数据库
drop database name;
drop database if exists name;
4. 显示数据库中的表
show tables;
5. 显示表头
desc tablename;
6. select去除重复字段
select distinct colname from tablename;
7. 删除表
drop table tablename;
8. 将表中的数据清空
delete from tablename;
9. 显示表中的记录
select * from tablename;
10. 建表
create table tablename
(
id int(3) auto_increment not null primary key,
name char(10) not null,
address varchar(50) default 'shenzhen',
year date
);
11. 插入数据
insert into tablename values('', 'test', 'test', '2000-01-01');
insert into tablename(name, address, year) values('test', 'test', '2000-01-01');
12. 创建一个超级用户
mysql> grant all privileges on *.* to user@localhost identified by 'password' with grant option;
13. 增加新用户
mysql> grant select on database.* to username@host identified by "password";
example:
mysql> grant all privileges on *.* to test@localhost identified by 'test' with grant option;
mysql> grant all privileges on *.* to test@"%" identified by 'test' with grant option;
14. 删除授权
mysql> revoke all privileges on *.* from root@"%";
mysql> delete from user where user="root" and host="%";
mysql> flush privileges;
15. 创建一个custom在特定的客户端登陆,可访问特定数据库test
mysql> grant select, insert, update, delete, create, drop on test.* to custom@test.com identified by 'password';
16. 重命名表
mysql> alter table t1 rename t2;
17. 备份数据库
bash# mysqldump -h host -u root -p dbname > dbname_backup.sql
18. 恢复数据库
bash# mysqladmin -h myhost -u root -p create dbname
1. 创建数据库
create database name;
2. 选择数据库
use databasename;
3. 删除数据库
drop database name;
drop database if exists name;
4. 显示数据库中的表
show tables;
5. 显示表头
desc tablename;
6. select去除重复字段
select distinct colname from tablename;
7. 删除表
drop table tablename;
8. 将表中的数据清空
delete from tablename;
9. 显示表中的记录
select * from tablename;
10. 建表
create table tablename
(
id int(3) auto_increment not null primary key,
name char(10) not null,
address varchar(50) default 'shenzhen',
year date
);
11. 插入数据
insert into tablename values('', 'test', 'test', '2000-01-01');
insert into tablename(name, address, year) values('test', 'test', '2000-01-01');
12. 创建一个超级用户
mysql> grant all privileges on *.* to user@localhost identified by 'password' with grant option;
13. 增加新用户
mysql> grant select on database.* to username@host identified by "password";
example:
mysql> grant all privileges on *.* to test@localhost identified by 'test' with grant option;
mysql> grant all privileges on *.* to test@"%" identified by 'test' with grant option;
14. 删除授权
mysql> revoke all privileges on *.* from root@"%";
mysql> delete from user where user="root" and host="%";
mysql> flush privileges;
15. 创建一个custom在特定的客户端登陆,可访问特定数据库test
mysql> grant select, insert, update, delete, create, drop on test.* to custom@test.com identified by 'password';
16. 重命名表
mysql> alter table t1 rename t2;
17. 备份数据库
bash# mysqldump -h host -u root -p dbname > dbname_backup.sql
18. 恢复数据库
bash# mysqladmin -h myhost -u root -p create dbname
- MySQL常用命令
- MySql常用命令
- MySQL常用命令
- mysql常用命令
- mysql常用命令
- mysql常用命令
- Mysql常用命令
- MySQL常用命令
- mysql 常用命令
- MySQL常用命令
- mysql常用命令
- MySql常用命令
- MySQL常用命令
- mysql 常用命令
- mysql常用命令
- mysql常用命令
- mysql 常用命令
- MySQL常用命令
- Server Application Unavailable出现的原因及解决方案集锦
- [转]百万级访问网站前期的技术准备
- paip. VS2010版本控制tfs使用总结
- HOW TO:在 Visual C# .NET 中设置窗口挂钩
- paip.svn使用小结
- MYSQL常用命令
- 关于初学者该选择学习ARM7还是ARM9的一点建议
- 视图合并(View Merging)
- Scala学习文档
- 暑假闭关计划
- Algorithms 学习笔记04 Sort
- paip.提升开发效率之查询界面
- ORA-04031错误的解决思路
- windowsphone7 消息推送Demo