mysql

mysql 开发进阶篇系列 39 mysql日志之二进制日志(binlog)

两盒软妹~` 提交于 2021-02-10 10:02:20
一.概述 二进制日志(binlog)记录了所有的DDL(数据定义语言)语句和DML(数据操纵语言)语句,但是不包括数据查询语句, 语句以"事件"的形式保存,它描述了数据的更改过程,此日志对灾难时的数据恢复起着极其重要的作用。    1.1 日志的位置和格式     在my.cnf中可以查看log-bin的位置,mysqld将包含所有更新数据的sql命令写入日志文件,位置如下图所示:          下面通过环境变量来查看当前binlog位置和状态 -- 通过环境变量来查看位置 SHOW VARIABLES LIKE ' %log_bin% '          下面查询所有binlog日志文件          上图中mysql-bin.index是日志的索引文件,记录了最大的日志序号。   1.2 日志的读取       由于日志以二进制方式存储,不能直接读取,需要用mysqlbinlog工具来查看。在33篇里有讲到开启binlog以及查看内容,这里不在详述。     https://www.cnblogs.com/MrHSR/p/9555313.html   1.3 日志的删除 对于繁忙的事务处理系统,每天会生成大量日志内容,日志如果长时间不清除,将会对磁盘空间带来很大的浪费,因此定期删除日志是DBA维护mysql数据库的一个重要工作内容,下面介绍几种方法。         

MySQL之二进制日志

天涯浪子 提交于 2021-02-10 09:50:17
一、Binlog日志格式 根据日志定义的格式不一样,可以分为Statement格式、Row格式或者MIXED格式 mysql5.6----》 | binlog_format | STATEMENT | mysql5.7---》 | binlog_format | ROW | 理解三种不同的格式 A: Statement格式 说明:基于语句的,记录操作的sql语句 优点: binlog文件大小较小 易于理解,方便阅读 日志中包含原始SQL,方便统计和审计 缺点: 存在安全隐患,可能导致主从不一致 对一些系统函数不能复制,比如sysdate,uuid等 不支持不确定的SQL语句 (以上格式不推荐使用,但是在mysql5.7以前都是默认的格式) B: Row格式 说明: 记录操作的每一行数据 优点: 相比statement更加安全的复制格式 系统的特殊函数也可以复制 更少的锁 数据一致性高 缺点: binlog 文件会比较大 无法从binlog中看见用户执行的SQL 每个表最好都要有一个主键 (推荐使用) 从mysql5.7之后,默认的格式为Row格式 Table_map: 记录表的元数据信息 ROWS_EVENT分为三种:WRITE_ROWS_EVENT,UPDATE_ROWS_EVENT,DELETE_ROWS_EVENT,分别对应insert,update和delete操作。

Django extra user registration details not saving to database

馋奶兔 提交于 2021-02-10 09:43:55
问题 I have been trying to extend the django user profile but it won't save the extra details to the database which is a user_type of business, student, tourist and I can't figure out why. Any help would be appreciated. It doesn't save in the DB as null, it is saving as just blank. Using python 3 with the latest version of django. Forms.py: from django import forms from django.contrib.auth.forms import UserCreationForm from django.forms import ModelChoiceField from django.contrib.auth.models

Bitnami. reset mysql root pwd

一个人想着一个人 提交于 2021-02-10 09:40:13
问题 How do I reset the root pwd and account in MySQL as I was following instructions how to grant priveledges for other servers and accidently tied root user (Mysql) to other ip address and now it seems that I can not log in as admin on localhost? Thanks 回答1: You have 3 ways to reset rootpass in mysql: 1 - launch the following command: sudo service mysql reset-password 2 - You can also try: `sudo dpkg-reconfigure mysql-server-x.x` 3 - The third solution is a bit longer but worked for me: `sudo

How do I connect and retrieve data from Google Cloud SQL using PHP?

给你一囗甜甜゛ 提交于 2021-02-10 09:37:08
问题 The only tutorials I could find used unfamiliar alternative resources, like app engine, composer, github, proxies, other plugins. Isn't it possible to simply connect to it using pure PHP? For example, in the following code would I need to modify to get data from Google Cloud SQL? <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!

How do I connect and retrieve data from Google Cloud SQL using PHP?

心不动则不痛 提交于 2021-02-10 09:36:43
问题 The only tutorials I could find used unfamiliar alternative resources, like app engine, composer, github, proxies, other plugins. Isn't it possible to simply connect to it using pure PHP? For example, in the following code would I need to modify to get data from Google Cloud SQL? <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!

Host is not allowed to connect to this MySQL server for client-server application

我与影子孤独终老i 提交于 2021-02-10 09:32:17
问题 I just exported my tables from one web host to another (AWS). Thinking everything would go smoothly (yeah right), well, everything that can go wrong has gone wrong. I get this error when trying to query my database (which I didn't get before): SQLSTATE[HY000] [1130] Host '<my ip address>' is not allowed to connect to this MySQL server This is the same error from this post: Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server The solution in that post seems to revolve around

Host is not allowed to connect to this MySQL server for client-server application

走远了吗. 提交于 2021-02-10 09:31:07
问题 I just exported my tables from one web host to another (AWS). Thinking everything would go smoothly (yeah right), well, everything that can go wrong has gone wrong. I get this error when trying to query my database (which I didn't get before): SQLSTATE[HY000] [1130] Host '<my ip address>' is not allowed to connect to this MySQL server This is the same error from this post: Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server The solution in that post seems to revolve around

2018年终盘点:阿里云数据库RDS核心能力演进

空扰寡人 提交于 2021-02-10 08:56:13
摘要: 2018年云数据库RDS发展上,不但针对MySQL、SQL Server、PostgreSQL提供了适合个人入门用户的基础版产品,以实惠的价格普惠广大中小用户。更加入最新的MariaDB TX企业版,及大幅度提高PPAS的Oracle兼容性,从企业需求出发,重点在全生命周期、全链路安全、全链路监控、全方位运维、多引擎覆盖 5个方面进行发力,为企业用户提供更优质的云数据库服务。 云计算已经进入普及期,不少企业开始从自建数据中心转向云计算。在云计算资源的使用上,从最开始只是使用IaaS层基础资源,转向使用包括云数据库在内的各类PaaS资源。数据库是企业IT架构的核心部分,RDS关系型数据库服务已经成为企业重度依赖的云服务。 过去7年的持续发展,2018年阿里云首次进入Gartner的数据库魔力象限,能够入选Gartner,这是中国数据库厂商的一次突破。阿里云入围Gartner充分说明,在新一波技术浪潮之上进行创新,才可能做出突破。云数据库已经不仅仅是简单地完成数据库在云资源中的搭建,数据库曾经是IT系统中最昂贵的投入之一。对企业CXO们(CEO、CFO、CTO、CIO等)而言,更加灵活的生命周期管理,可以实现成本的合理投入及灵活管理。对DBA技术人员而言,更高的安全性、更全面的监控能力、更便捷的运维方式,将改变DBA在企业的工作模式及地位。 从企业管理者及DBA的角度

How to exclude rows when using a LEFT JOIN (MySQL)

心已入冬 提交于 2021-02-10 08:06:46
问题 I have users with many posts . I want to build an SQL query that would do the following in 1 query (no subquery), and hopefully no unions if possible. I know I can do this with union but I want to learn if this can be done using only joins. I want to get a list of distinct active users who: have no posts have no approved posts Here's what I have so far: SELECT DISTINCT u.* FROM users u LEFT JOIN posts p ON p.user_id = u.id LEFT JOIN posts p2 ON p2.user_id = u.id WHERE u.status = 'active' AND