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 数据库管理的基本命令,包括创建、选择、删除数据库,显示数据库信息,建表、插入数据,授权与权限管理等核心操作。
8978

被折叠的 条评论
为什么被折叠?



