variable log_bin value off - what does it mean? - mysql

I've edited my.cnf file to enable binary logging. Configuration I used is as follows:
[ mysqld ]
log-bin= /var/lib/mysql/localhost-mysql-bin.log
binlog-format = mixed
than I logged in as root to my server (on my computer, localhost that is) and used following command to check whether my bin_log is actually on:
SHOW VARIABLES LIKE 'log_bin';
and I got this:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | OFF |
+---------------+-------+
From what I gather is that I didn't suceed. Or does it mean that I haven't got any logs yet?

OK, so there was nothing wrong with my configuration. Simple restart did the job and mysql picked up on changes. Problem solved.

Related

how to set mysql general_log_file path to shared folder in laravel homestead

I'm using laravel homestead, and for purposes I need to have quick access to mysql general_log_file in my windows shared folder. I started with this:
mysql> SET GLOBAL general_log_file = '/home/vagrant/code/mysql.log';
I also removed secure_file_priv from mysql setting, now I get:
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
+------------------+-------+
I even gave Give Root Privileges to mysql via this method, but I still get this error:
Can't create/write to file '/home/vagrant/code/mysql.log' (OS errno 13 - Permission denied)
while trying:
mysql> SET GLOBAL general_log = 'ON';
any idea how can I solve this irritating problem?
I know of two things to check that are likely causes. I've experienced both of these in a vagrant environment.
The directory is not writeable by the Linux uid of the mysqld process.
The Linux kernel is restricting the paths accessible to mysqld through Apparmor (Ubuntu or Debian) or SELinux (CentOS or RHEL). The error reported is a permission error, even if the file permissions appear to allow the mysql user to write to that location. You must either disable the apparmor/selinux or else configure it to allow the alternative location.
Since you're only using a VM, I'd just disable it, unless you would like to learn how to configure it in case you need to do that in a non-VM environment.
PS:
secure_file_priv is totally irrelevant to this issue. That option affects only LOAD DATA INFILE and SELECT ... INTO OUTFILE.

Where to add my.cnf configuration file for mysql in mac Catalina OS

I need to load data into mysql and for that i need to add this file or edit this file. I am not able to find this file and create into the right location.
I tried adding file in my root.
[mysqld]
secure_file_priv = ''
Its still coming as null.
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
I tried adding the file here also but it did not work.
/usr/local/mysql/support-files
Mysql is not picking this configuration up.
You can create file like /etc/my.cnf and
if you want to see example file on mac you can get at /usr/local/mysql/support-files/.

MySQL server has gone away error. --max_allowed_packet=2G doesn't work either

I am constantly getting the following error while trying to import a MySQL table.
ERROR 2006 (HY000) at line 15692: MySQL server has gone away
The error occurs when inserting entries of a table with a longblob field. I have tried everything suggested on the internet, like using --max_allowed_packet, export and import explicity in utf8, exporting in --hex-blob, increasing wait_timeout and interactive_timeout etc, but nothing works!
I dug a bit deeper and noticed that the value of --max_allowed_packet isn't being set properly. I am using LAMPP, and in the file /opt/lampp/etc/my.cnf, I have the following under the [mysqld] section.
max_allowed_packet = 2G
However, MariaDB still shows that its value is set to only 1 MB. Why is it like that? I stopped and restarted LAMPP server, but still to no avail. Even setting this parameter from the command line, like as follows, doesnt' work!
/opt/lampp/bin/mysql -h localhost --max_allowed_packet=2G -u root -p
In both cases, when I query its value, I get the following.
MariaDB [(none)]> SHOW VARIABLES LIKE 'max_allowed_packet';
--------------
SHOW VARIABLES LIKE 'max_allowed_packet'
--------------
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
How can I solve this problem? Note that I am logged in as root.
OK, I have solved the problem. Shown below, is how I did it.
Inside an MySQL shell (open one by typing/opt/lampp/bin/mysql -h localhost -u root -p), set the value of max_allowed_packet, like this.
SET GLOBAL max_allowed_packet=1073741824;
After exiting that MySQL shell, this value should have been set. If you now go back to a new MySQL shell, and type the following,
SHOW VARIABLES LIKE 'max_allowed_packet';
It displays the correct value, as shown below.
+--------------------+------------+
| Variable_name | Value |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+

Why MySQL disable load local infile is not working?

As part of security hardening, I am trying to disable local_infile and Prevent someone accessing local files of Operating System. As per the documentation I can disable it by either setting the variable local-infile=0 in my.cnf or start mysqld service with option --local-infile=0. But with any of the option I am able to load the local files.
I tried first adding in /etc/my.cnf
[mysqld]
local-infile=0
After that I confirmed the changes got reflected.
mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | OFF |
+---------------+-------+
1 row in set (0.00 sec)
Then from mysql client I loaded the local file using load_file
mysql> SELECT load_file("/etc/passwd");
The above command shows the content of /etc/passwd file, even though local_infile is disabled.Can someone tell what is going wrong here?
I repeated the same steps from passing mysqld --local-infile=0 but no change. I have also tried starting mysql client with --local-infile=0 option but no difference.
Use this query in your mysql database
STEP:1
SHOW GLOBAL VARIABLES LIKE 'local_infile';
STEP:2
SET GLOBAL local_infile = 'ON';
STEP:3
SHOW GLOBAL VARIABLES LIKE 'local_infile';

Where can I find the MySQL log file in XAMPP

I use PHP to access MySQL in XAMPP. My question is where I can find the MySQL log file if there is a DB error.
Also, can I change the default location/name of that log file?
Thank you
///// Based on the coments //////
mysql> show variables like '%log_file%';
+---------------------------+------------------------------------+
| Variable_name | Value |
+---------------------------+------------------------------------+
| general_log_file | C:/xampp/mysql/data/mysql.log |
| innodb_log_file_size | 5242880 |
| innodb_log_files_in_group | 2 |
| slow_query_log_file | C:/xampp/mysql/data/mysql-slow.log |
+---------------------------+------------------------------------+
4 rows in set (0.00 sec)
If you do
SHOW VARIABLES LIKE '%log_file%';
it will show exactly where they're being written.
The accepted answer is a bit old, for MySQL 5.1+
you may use the queries:
SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = 'my_log.log';
First will enable loging (which may be off by default)
and the second select updates the preferred file (by default under C:/xampp/mysql/data/).
NOTE: On windows 8 you may have to run your SQL IDE as ADMINISTRATOR for this commands to get saved.
NOTE2: you can also set this in the config, go to path_to_xampp/mysql/ and edit my.ini
(copy from my-default.ini if it does not exists) and add the settings there:
[mysqld]
general_log = 'ON';
general_log_file = 'my_log.log';
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
It's a *.err file.
You will find it here : C:\xampp\mysql\data
To trace you error correctly, open it with Notepad++ for example and Start Mysql. You Should see the error at the end of the file.
You can also try looking at localhost/phpmyadmin/ and click on the Variables tab.
On mac, it's likely to be at:
/Applications/XAMPP/xamppfiles/var/mysql
If there are a lot of error files there, do ls -la to see which one is most recent and most likely.