MySql命令大全

MySql内置函数


1. 显示当前选择的数据库:select database();
2. 为字符串密码加密:password();
3. 查询数据库版本:select version();
4. 查询当前日期、时间:select current_date(); select current_time(); select now();
5. 查询当前用户:select user();

 

MySql基本命令


1. 登录数据库:mysql -h主机地址 -u用户名 -p用户密码 default_DB; mysql
2. 显示所有数据库:show databases;
3. 显示当前选择数据库中的所有表:show tables; show tables like 'tblUser%';
4. 获取表结构:desc <tableName>; show columns from <tableName>;
5. 重命名表:rename table 原表名 to 新表名
6. 查询某几行数据:select * from <tableName> limit <起始行号>,<查询行数>;
7. 为表增加字段:alter table <tableName> add column <columnName> char(5) default '0';
8. 如果数据库存在删除:drop database if exists <dbName>;
9. 多项数值同时插入:insert into <tableName>(c1,c2,c3) values (v1,v2,v3),(vv1,vv2,vv3),(vvv1,vvv2,vvv3);
10. 数据库重新加载授权表:flush privileges;
11. 将文本文件中的数据装载到表中(tab分割):load data local infile '~/mydata.txt' into table <tableName>;
12. 将文本文件中的数据装载到表中(,分割):load  data local infile '~/mydata.txt' replace into table 'tableName' fields terminated by ',' lines terminated by '/n'('field1' , 'field2');
13. 使用/c取消已经输入的命令
14. 查看创建表时的comment字段内容:show full fields from <tableName>; 

 

MySql管理命令


1. (不常用)修改mysql中用户userA的密码:update user set password=password('newp') where user = 'userA';
2. 增加一个用户test,密码为abc123,让他只可在localhost登录,并只可对数据库mydb进行查询、插入、修改、删除的操作:grant select, insert, update,delete on mydb.* to test@localhost identified by "abc123";
3. 增加一个没有密码的用户:grant all on *.* to test@172.168.1.1 indentified by "";

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值