关于mysql:mysql常用语句

40次阅读

共计 847 个字符,预计需要花费 3 分钟才能阅读完成。

登录(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_posts1 where id = 42;

更新:

update wp_users SET user_email='xx@qq.com';

替换更新:(批改 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;

正文完
 0