MySql教程

MySQL 语句汇总

本文主要是介绍MySQL 语句汇总,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

mysql -u 用户名 -p 密码 -h 主机名
主机名(形如:192.168.231.129)
show databases;
use 数据库名
show tables;
show function status;
show procedure status;
show table status;
show table status where comment=‘view’;
select * from information_schema.views;
show create table 表名\视图名;
show create function 函数名;
show create procedure 过程名;

rand()*10;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0.1~9.9
ceil(rand()*10);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1~10
floor(rand()*10;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0~9

convert(数字,char(数字转化成字符的个数));
lpad(‘字符串’,字符串要达到的长度值,‘不够长度时使用这里的内容进行填充’);
rpad(char,n,char);
concat(char,char,char,char…);
if(条件判断,成立时取这里值,不成立时取这里的值);
describe 表名;
describe 视图名; 但字段不显示

mysql> select now();

		+---------------------+
		| now()               |
		+---------------------+
		| 2022-01-20 16:48:11 |
		+---------------------+

mysql> select replace(now(),’ ‘,’’);

		+-----------------------+
		| replace(now(),' ','') |
		+-----------------------+
		| 2022-01-2016:49:38    |
		+-----------------------+

mysql> select replace(replace(now(),’ ‘,’’),’:’,’’);

		+---------------------------------------+
		| replace(replace(now(),' ',''),':','') |
		+---------------------------------------+
		| 2022-01-20165154                      |
		+---------------------------------------+

mysql> select replace(replace(replace(now(),’ ‘,’’),’:’,’’),’-’,’’);

		+-------------------------------------------------------+
		| replace(replace(replace(now(),' ',''),':',''),'-','') |
		+-------------------------------------------------------+
		| 20220120165350                                        |
		+-------------------------------------------------------+

select table_name from information_schema.tables where table_name like ‘ST2%’ into @tn;
set @bl=concat('select * from ‘,@tn, ’ limit 1118,5’);
prepare ex from @bl;
execute ex;
上述语句解决,查询语句的表名是变量遇到的问题。

这篇关于MySQL 语句汇总的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!