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;
上述语句解决,查询语句的表名是变量遇到的问题。

上一篇:【考试总结】2022-01-21


下一篇:[学习笔记] 计算几何模板