mysql常用语句

登录(root用户,然后输入密码):

mysql -u root -p

显示所有数据库:

show databases;

使用哪个数据库:

use wordpress;

显示当前数据库下的所有表:

show tables;

限制显示条数的查询:

select * from wp_options limit 10;

条件查询:

select * from wp_options where option_id = '1';

模糊查询(必须结合%(任意字符),不然跟=效果一样):

select * from wp_options where option_value like 'http%';

表字段查询:

show columns from wp_postmeta;
// or
describe wp_postmeta;

根据id查询某个表的某个字段:
select post_title from wp_posts where id = 42;

更新:

update wp_users SET user_email='[email protected]';

替换更新:(修改user_email字段,把qq.com替换为weixin.com)

update wp_users SET user_email=replace(user_email, 'qq.com', 'weixin.com');

更新操作,一定要慎重。最好先备份再update。不然一定要看清楚。另一个就是加上binlog,以便回滚。

备份:
mysqldump -uroot -p -B wordpress > /var/www/mysqlbackup/xxx.sql

删除:
delete from wp_postmeta where meta_id = 85;

一般排序:
select * from wp_postmeta where meta_key = 'post_views' order by meta_value;

longtext类型排序:
select * from wp_postmeta where meta_key = 'post_views' order by cast(meta_value as decimal) desc;

你可能感兴趣的:(mysql)