MYSQL常用命令
2012-07-29 00:33
169 查看
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常用命令2---授权、启动、启动服务
- mysql的常用命令增删改查系列语句
- 设置mysql用户密码(5.6/5.7)、远程连接数据库、常用命令
- MYSQL常用命令
- 设置mysql远程登录和常用命令
- MySQL 常用命令
- MySQL处理数据库和表的常用命令
- mysql常用命令
- MySQL监控所用到的常用命令
- mysql 常用操作命令
- MySQL导入.sql文件及常用命令
- mysql操作常用命令
- MySQL导入.sql文件及常用命令
- mySQL常用命令、语句
- MySql 常用命令
- MySql常用命令总结
- MYSQL常用命令
- mysql常用命令总结