This question is about MySQL binary logs.
We need to move a binary log to a different hard disk.
What is the configuration change required in MySQL?
Currently binary logs go into the same folder as the ibdata and there is a replication slave running which needs the binary logs.
Changing the log-bin works. BUT you need to copy the log-bin files first to the new location and modify the index file. If you dont'do this you will break your remote slave with the error:
Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
More info here:
http://freebsd.down-to-details.com/sys-admin/relocating-moving-mysql-binlogs/
From the way I read the doc, you can specify a path on the log-bin config.
To enable the binary log, start the
server with the --log-bin[=base_name]
option. If no base_name value is
given, the default name is the value
of the pid-file option (which by
default is the name of host machine)
followed by -bin. If the basename is
given, the server writes the file in
the data directory unless the basename
is given with a leading absolute path
name to specify a different directory.
It is recommended that you specify a
basename; see Section C.5.8, “Known
Issues in MySQL”, for the reason.
Related
In WAMPs MySQL my.ini file you can specify the location of the mysql error log file, but if I try setting this variable in the my.ini of MariaDB it will not start. I assume it is not recognizing the variable, which worked fine in WAMP.
How do I set the MySQL error log file when using MariaDB?
MariaDB uses a separate option called log-basename
--log-basename=name (for example if name is mypc then mypc.err will be created as a error log)
Basename for all log files and the .pid file. This sets all log file names at once (in 'datadir') and is normally the only option you need for specifying log files.
This is especially recommend to be set if you are using replication as it ensures that your log file names are not depending on your host name. Sets names for --log-bin, --log-bin-index,--relay-log, --relay-log-index, --general-log-file, --log-slow-query-log-file, --log-error-file, and --pid-file.
I am storing images in MYSQL.
I have table as
CREATE TABLE myTable (id INT, myImage BLOB);
When I am trying to insert 4.7MB file, I am getting exception as
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4996552 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
I believe this is related to image size only. Is there any other variable type that I can use?
Update 1
As per older SO question, I also tried with MEDIUMBLOB but still I am getting same error.
Adding Image to a database in Java
Update 2
At the start of the project, I execute below query and everything is working now
SET GLOBAL max_allowed_packet = 1024*1024*14;
As the error says, it has nothing to do with variable type but rather the max_allowed_packet variable:
You must increase this value if you are using large BLOB columns or long strings. It should be as big as the largest BLOB you want to use. The protocol limit for max_allowed_packet is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.
But, generally speaking, don't store files in your database - store them in your filesystem and record the path to the file in the database.
For Windows users:
mysql_home points to your mysql/mariadb installation folder.
open cmd, cd to %mysql_home%\bin and run mysqladmin > temp.txt This will spit out a lot of information about the usage of the tool. Somewhere among all that output you will find this information:
Default options are read from the following files in the given order:
C:\windows\my.ini C:\windows\my.cnf C:\my.ini C:\my.cnf c:\mariadb-5.5.29-w
inx64\my.ini c:\mariadb-5.5.29-winx64\my.cnf
This shows that you could have, if you don't have it already, a file called my.ini or my.conf in the %mysql_home% directory.
create my.ini and add the lines:
[mysqld]
#allow larger BLOBs to be stored
max_allowed_packet = 10M
make sure to include the settings group which is [mysqld] otherwise it will fail to start (and for me it ended up hanging in limbo).
You will now need to restart the MySQL daemon, this is done either by killing and starting the currently running mysqld process or by restarting the MySQL service (run services.msc, locate MySQL, press the restart button; or from cmd, net stop MySQL followed by net start MySQL).
Following worked for me
edit my.cnf file ( mine was in /etc/mysql )
Then modify the max_allowed_packet value
I set it to
max_allowed_packet=200M
Make sure you restart MySQL for change to take effect
If working with AWS RDS, max_allowed_packet can be modified using DB Parameter Groups
The max_allowed_packet variable has a default value set in the configuration file (my.ini in my case). If your application tries to execute a query whose packet size exceeds this value, this exception is thrown.
My setup is on a Windows 10 machine with MySQL Server 8.0.
I copied the my.ini file with my desired value (64M) for max_allowed_packet to the various possible locations (C:\my.ini, C:\Windows\my.ini). Then restarted the mysql server. It didn't work. When I queried the database for the max_allowed_packet variable, the value remained unchanged.
The following steps worked:
I discovered that there is a my.ini file at a different location.
Open the my.ini file at the following location C:\ProgramData\MySQL\MySQL Server 8.0. This has lots of entries, besides max_allowed_packet.
Locate the entry for max_allowed_packet, and set it to the desired value (for e.g. 64M).
Save and close the my.ini file.
Restart the MySQL80 service.
Log into to the mysql server prompt and run the query
show variables like 'max_allowed_packet';
You should see the value set to your desired value.
I have problem with wammp server.
In directory "..\WampServer\bin\mysql\mysql5.5.8\data" was created files with very large size.
Full size of this directory is 50GB. What is these files? How can I fix this problem?
The names of files are:
mysql-bin.000001
mysql-bin.000002
................
mysql-bin.000227
The size of all files is 49GB
Thanks in advance!
By default whenever you make a change to a MySQL database it creates a log of the query and stores it in a file simlare to mysql-bin.000001. The MySQL database does this so that you can recover or replicate a database. Most applications this is a good things to have enabled just like doing regular backups.
If you want to disable MySQL from creating these binary logs:
Open my.ini
Search for this line log-bin=mysql-bin
Comment this line out by adding a hash mark: # log-bin=mysql-bin
Save and restart the MySQL database
You can now safely delete these files from that directory.
I did another thing on my wamp...
http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html
Start a command prompt and goto directory wamp\bin\mysql\mysql5.5.16 or whatever version number you got
type:
mysql.exe -u root
SHOW BINARY LOGS;
a list with all the log files will be show up. We need the last one.
In my case was mysql-bin.000412
so i typed
PURGE BINARY LOGS TO 'mysql-bin.000412';
and you are ok!
I've got a replication set up on pair of servers. One is a master and second is a slave.
Recently on master the binlog files were purged too early (by filename so mysql haven't prevented too early removal of file).
Now the SLAVE has status:
Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
I wan't to restore the missing binlog files so the slave will restart reading from the point it finished.
The files are already in place but how can I force master to 'unpurge' it's log list (so they are visible in SHOW BINARY LOGS)?
Ok I made it. However this solution isn't perfect/100% safe.
I've entered all filenames to my mysql-bin.index
find /var/log/mysql/ -wholename '/var/log/mysql/mysql-bin.0*' | sort > mysql-bin.index
(if you will use it check the filename format in mysql-bin.index file first and adjust to your needs)
Then restart mysql and mysql reloads that file on start.
the MASTER is ready.
Now it's enough to do
SLAVE STOP;
and
SLAVE START;
on SLAVE and it will continue his job.
Does MySQL keep a transaction log and if so where could I find it?
A number of rows have mysteriously been deleted from a table and I want to try and see how and when it occurred.
If you turned on - mysql can track binary log, which contains all the modifications (to be clear - it contains the queries that had changed something).
But anyway, it is useless if you do not have the initial dump, which precedes the binlog turning on. Also i suppose if you made the dump and turned on binlog - you would not ask such question :-S
Short answer: not by default.
In order to have accurate logging results, you need to have started the server in binary logging mode first, using the parameter --log-bin=your-file-name. It then creates a binary log file {your-file-name.seq} where seq is a sequence number for subsequent log files (recommended to put your file name there, with explicit directory location).
More information on the MySQL site explaining all the details: https://dev.mysql.com/doc/refman/5.7/en/binary-log.html
If you're using MySql on Windows, there's a file located in C:\Program Files\MySQL\MySQL Server 5.0\data (assuming a C: drive for the installation target and MySql version 5.0), that is called %COMPUTERNAME%.log that contains the commands that have been executed.