1、突然不记得数据库的密码了,导致登录数据的时候一直报“access denied for user root '@' localhost解决”这个错误。
我的做法是在root权限下查看数据库的配置文件,找密码,linux下一般是/etc/mysql/my.cnf或者/etc/mysql/debian.cnf
2、创建数据库函数时,你一次性输入所有函数内容或者当你打完一句分号‘;’,‘enter’回车的时候就报语法错误,那应该是设置边界符的问题,一般的做法是在创建函数之前输入‘delimiter //’,输完整个函数再以‘//’结尾,这里有个疑惑的地方就是'quit'退出时,不用加分号‘;’就可以退出,当然你可以ctrl+c强行退出。
3、mysql中字符拼接有concat函数跟concat_sw函数,转义字符例如" ' '符号可以" \' "这样。
详见此链接:http://www.cnblogs.com/end/archive/2011/04/01/2002516.html
以及http://zac110.iteye.com/blog/1582382
4、linux下查看磁盘大小df -h。查看xx软件安装位置whereis xx,运行位置which xx
5、mysql 创建函数的1418错误解决方案
提示:Error Code : 1418
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
(0 ms taken)
处理过程:
登陆mysql数据库
> set global log_bin_trust_function_creators = 1;
> start slave;
6、数据库函数创建以及执行过程,以及一些查看命令
详情见:http://www.netpc.com.cn/943.html
7、mysql修改数据表字段长
alter table 表名 modify column 字段名 类型;
例如
数据库中user表 name字段是varchar(30)
可以用
alter table user modify column name varchar(50) ;
8、查看数据库的大小
摘抄:https://www.jianshu.com/p/cc20d90ac138
a、进入information_schema 数据库(存放了其他的数据库的信息)
use information_schema;
b、查询所有数据的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
c、查看指定数据库的大小: 比如查看数据库home的大小 select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';
d、查看指定数据库的某个表的大小
比如查看数据库home中 members 表的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';
9、shell生成指定范围的随机数
详情见:https://blog.csdn.net/fdipzone/article/details/24329523
摘抄:
#!/bin/bash
function rand(){
min=$1
max=$(($2-$min+1))
num=$(cat /proc/sys/kernel/random/uuid | cksum | awk -F ' ' '{print $1}')
echo $(($num%$max+$min))
}
rnd=$(rand 100 500)
echo $rnd