当前位置:网站首页>mysql使用常见问题
mysql使用常见问题
2022-07-22 10:42:00 【roo_1】
limit offset用法
例1,假设数据库表student存在13条数据。
代码示例:
语句1:select * from student limit 9,4
语句2:slect * from student limit 4 offset 9
// 语句1和2均返回表student的第10、11、12、13行
//语句2中的4表示返回4行,9表示从表的第十行开始
例2,limit和offset用法
mysql里分页一般用limit来实现
- select* from article LIMIT 1,3
2.select * from article LIMIT 3 OFFSET 1
上面两种写法都表示取2,3,4三条条数据
当limit后面跟两个参数的时候,第一个数表示要跳过的数量,后一位表示要取的数量,例如
select* from article LIMIT 1,3 就是跳过1条数据,从第2条数据开始取,取3条数据,也就是取2,3,4三条数据
当 limit后面跟一个参数的时候,该参数表示要取的数据的数量
例如 select* from article LIMIT 3 表示直接取前三条数据,类似sqlserver里的top语法。
当 limit和offset组合使用的时候,limit后面只能有一个参数,表示要取的的数量,offset表示要跳过的数量。
例如select * from article LIMIT 3 OFFSET 1 表示跳过1条数据,从第2条数据开始取,取3条数据,也就是取2,3,4三条数据
mysql密码特殊字符处理
1、密码加单引号
2、特殊字符前面加上转义
mysql自动化安装
1、需要的rpm包
下载rpm包网址
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
2、自动化安装脚本
参考安装的文档
#!/bin/bash
mkdir mysql_install
tar xf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar -C mysql_install
cd mysql_install
rpm -qa | grep mariadb
yum -y remove mariadb-libs
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
echo "----------install success!!!!"
systemctl start mysqld
sleep 1
systemctl enable mysqld
sleep 1
systemctl status mysqld
# 获取密码
#MYSQL_PASSWD=`cat /var/log/mysqld.log | grep password | head -1 | rev | cut -d ' ' -f 1 | rev`
# 修改密码
password=`grep "password" /var/log/mysqld.log | head -n 1`
install_passwd=${password:91:103}
echo "install_passwd: ${NEW_PASSWORD}"
echo "[mysql]" >> /etc/my.cnf
echo "user=root" >> /etc/my.cnf
echo "password=\"${install_passwd}\"" >> /etc/my.cnf
NEW_PASSWORD='Qaz123456!'
mysql --connect-expired-password -e "alter user 'root'@'localhost' identified by '$NEW_PASSWORD';"
sed -i '$d' /etc/my.cnf
sed -i '$d' /etc/my.cnf
sed -i '$d' /etc/my.cnf
echo "----------change password success!!!!"
sleep 1
# mysql给root开启远程访问权限
mysql -uroot -p${NEW_PASSWORD} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$NEW_PASSWORD';flush privileges;"
echo "----------set PRIVILEGES success!!!!"
sleep 1
# mysql开启binlog、和event
echo 'server_id=2' >> /etc/my.cnf
echo 'log_bin=mysql-bin' >> /etc/my.cnf
echo 'binlog_format=ROW' >> /etc/my.cnf
echo 'expire_logs_days=30' >> /etc/my.cnf
echo 'event_scheduler=ON' >> /etc/my.cnf
systemctl restart mysqld
echo "----------set binlog success!!!!"
3、按住过程中遇到的问题
获取密码找到的解决方法
MYSQL_PASSWD=`cat /var/log/mysqld.log | grep password | head -1 | rev | cut -d ' ' -f 1 | rev`
自己的解决方法,学习使用Linux获取字符串的方法
password=`grep "password" /var/log/mysqld.log | head -n 1`
install_passwd=${password:91:103}
echo "install_passwd: ${NEW_PASSWORD}"
mysql关闭ssl
skip_ssl
show global variables like ‘%ssl%’;
边栏推荐
- AMBert
- 1068 find more coins (30 points)
- 1076 forwards on Weibo (30 points)
- Deformable Detr paper accuracy, and analyze the network model structure
- 结构体和联合体
- Parasitic sensing common centroid binary weighted capacitor layout generation integrates layout, wiring, and cell capacitor size
- 测试用例设计
- Pytorch不同层设置不同学习率
- Latex compiles and reports errors in vscode `recipe terminated with error Retry building the project.
- VSCODE 比较两个文件
猜你喜欢
C language (Itoa function)
Pytoch sets different learning rates at different levels
【keil软件】仿真时如何使用逻辑分析仪查看波形
【FPGA】:ip核---乘法器(multiplier)
Binary search (recursive function)
二分查找(递归函数)
【FPGA】:ip核--Divider(除法器)
ASP.NET Core部署手册:4.注意事项和问题排查
A new checkerboard placement and sizing method for capacitors in charge scaling DAC based on nonlinear worst-case analysis
Rag summary
随机推荐
类的属性新建(初级理解)
进程fork
1034 Head of a Gang (30 分)
Common centroid capacitor layout generation considering device matching and parasitic minimization
pytorch 动态调整学习率,学习率自动下降,根据loss下降
postman接口测试
Vimplus modifies the terminal font to droid Sans Mono nerd font
DETR 論文精讀,並解析模型結構
【面试:基础篇04:插入排序】
[FPGA]: IP Core - - DDR3
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
C language (Itoa function)
Constructive common centroid placement and routing of binary weighted capacitor arrays
Highly configurable and scalable spiral capacitor design for high-density or high-precision applications
Matching of MOS transistors with different layout styles
Pytorch dynamically adjusts the learning rate, and the learning rate automatically decreases according to loss
【文献阅读与想法笔记13】Pre-Trained Image Processing Transformer
考虑器件匹配和寄生最小化的共质心电容器布局生成
DETR 论文精读,并解析模型结构
YOLO v1、v2、v3