Mariadb configuration is not loaded from my.cnf - mysql

My mariadb configuration in my.cnf is not getting loaded for "log-error" and "pid-file". I have checked other configurations params are loaded.
[root#kvm10 ~]# cat /etc/my.cnf
[mysqld]
!includedir /etc/mysqld/conf.d
datadir=/mnt/mgmt/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
tmpdir=/mnt/mgmt/var/lib/mysql_tmp
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
### TRT-3229 #####
sync_binlog=1
innodb_flush_method=O_DIRECT
innodb_support_xa = 1
myisam_repair_threads = 2
myisam_recover_options = FORCE
###################
innodb_file_per_table=1
innodb_log_buffer_size = 8M
table_open_cache=256
max_heap_table_size=256M
### TRT-4685 ###
max_connections=500
################
innodb_log_file_size = 512M
[mysqld_safe]
log-error=/var/log/mariadb/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root#kvm10 ~]#
But the configuration value for log-error & pid-file is not picked by MariaDB.
[root#kvm10 ~]# mysql -e "show variables like 'pid_file'"
+---------------+-----------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------+
| pid_file | /mnt/mgmt/var/lib/mysql/kvm10.pid |
+---------------+-----------------------------------+
[root#kvm10 ~]# mysql -e "show variables like 'log_error'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_error | |
+---------------+-------+
[root#kvm10 ~]#
Am I missing somethig or making some mistake. I have checked the files permissions in /var/log/mariadb/mysqld.log & /var/run/mysqld/mysqld.pid.

These options from the config file should be picked up if you start the server by running mysqld_safe, either directly or via the old-style init script (MariaDB 5.5/10.0 or older Linux distributions). If you have MariaDB 10.1+ and Linux distributions with systemd support and start MariaDB server via the service, mysqld_safe is not used.
Another reason why they might not work is if you start mysqld_safe without --defaults-file option, and there is another config file somewhere else in default locations which overrides these options.
1) Add the options to [mysqld] section of the config file, restart the server and see if it helps.
If it doesn't help,
2a) if you run MariaDB server via systemd service, check the service configuration, maybe there is something in there;
2b) if you run MariaDB server via mysqld_safe, try to start it with --defaults-file=/etc/my.cnf, to make sure that this, only only this config file is used.

Related

MariaDB on CentOS 7 refuses to read some updated variables

I'm trying to change max_connections and open_files_limit for MariaDB version 5.5.60 on CentOS 7.
Since there could be multiple my.cnf files, I used mysql --help --verbose to get possible locations. Here's the output:
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The /etc/mysql/my.cnf doesn't exist and .my.cnf isn't in my user directory, /root/ or mysql user's directory (which doesn't exist to begin with).
So I'm left with /etc/my.cnf. This is what it looks like:
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections = 5000
open_files_limit = 10240
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
The /etc/my.cnf.d from the last line contains server.cnf, which includes these two lines:
[server]
max_connections=5000
open_files_limit=10240
However, when I run systemctl restart mariadb, only the max_connections is changed, but I just can't get it to read the new value of open_files_limit.
It keeps doing this:
MariaDB [(none)]> SHOW VARIABLES LIKE 'open_files_limit';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| open_files_limit | 1024 |
+------------------+-------+
1 row in set (0.00 sec)
Do you have any idea why it's doing this and how I could get the server to read the new value of open_files_limit?
Thank you in advance
Sasha
The value of open_file_limits variable can't be higher than your system limits.
Check output of ulimit -n and change your system configuration. Preferable assign these limits not system wide, but for the user under which MariaDB server is running.

Still can't enable the slow query log

Environment
This is my environment:
System: CentOS 7
virtual machine, created by virtualbox, only mysql installed
MySQL: 5.7.35
Setup MySQL by this chinese toturial: link
my.cnf:
[mysqld]
# slow query log
slow_query_log=on
slow_query_log_file=/var/log/mysql/slow_query.log
long_query_time=1
# UTF-8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server=utf8
# disable case sensitive
lower_case_table_names=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8
I have created the log file and executed these as root:
chown -R mysql:mysql /var/log/mysql
service mysqld restart
Problem
The slow query log is not enabled
When I try this in mysql as root:
show variables like '%slow%';
It shows these:
+---------------------------+-------------------------------+
| Variable_name | Value |
+---------------------------+-------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /var/log/mysql/slow_query.log |
+---------------------------+-------------------------------+
Tried
When I try to enable the query log manually:
set global slow_query_log = ON;
Error
ERROR 29 (HY000): File '/var/log/mysql/slow_query.log' not found (Errcode: 13 - Permission denied)
others:
add general_log=on under [mysqld] in my.cnf
replace on or ON by number 1
Did I do anything wrong?
Maybe a simple stupid mistake but I can't figure it out...
Thank you very much
Given the directory ownership is correct, and that its Centos7, you'll need to fix the selinux permission.
The manual entry is on this page using mysqld_log_t, the same as the error log, because that will allow logrotate rules to access it.
semanage fcontext -a -t mysqld_log_t /var/log/mysql/slow_query.log
Then you should be able to enable, even at runtime:
set global slow_query_log = ON;
There are far too many settings to get it right:
log_output = FILE
slow_query_log = ON
slow_query_log_file = (fullpath to some file)
long_query_time = 1
log_slow_admin_statements = ON
log_queries_not_using_indexes = OFF
More discussion and more options: http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog

Where does the mariadb logs exists

I am using mariadb and I to investigate some issue I wanted to check the logs. To my surprise, log file is not generated for mariadb.
I suspect this cannot be the case so I am doubting my search skills.
MariaDB [(none)]> show variables like 'log_error'
-> ;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_error | |
+---------------+-------+
1 row in set (0.00 sec)
I have added the entry in my.cnf still above field is coming to be empty.
[root#cslcodev11-oem ~]# cat /etc/my.cnf
[mysqld]
!includedir /etc/mysqld/conf.d
datadir=/mnt/mgmt/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
tmpdir=/mnt/mgmt/var/lib/mysql_tmp
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
### TRT-3229 #####
sync_binlog=1
innodb_flush_method=O_DIRECT
innodb_support_xa = 1
myisam_repair_threads = 2
myisam_recover_options = FORCE
###################
innodb_file_per_table=1
innodb_log_buffer_size = 8M
table_open_cache=256
max_heap_table_size=256M
### TRT-4685 ###
max_connections=500
################
innodb_log_file_size = 512M
[mysqld_safe]
log-error=/var/log/mariadb/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root#cslcodev11-oem ~]#
So, I want to know do we have any default location where these logs are getting generated, if the path cannot be read from config files.
Update:
After some investigation, I found this information,
Reference: https://mariadb.com/kb/en/mariadb/error-log/
Activating the Error Log
The error log is active by default. The log-error=filename option determines where the output will be written. If no file name is specified, the log will be written to host-name.err. If no absolute path is specified, the file will be written to the data directory (determined by the value of the datadir system variable).
On Unix systems, if the --log-error option is not used, the errors are written to stderr (usually, the command line).
On Windows, if the --console option is specified, and --log-error is not used, the errors are written to the console. If --log-error is present, --console is ignored.
So now I understand that due to some reason the configuration log_error in my.cnf is not considered. So as per the suggestion, on Unix system, if --log-error is not used, logs are redirected to stdout.
BUT, I am starting the service using service mysqld start command so I want to know what all options are used by default when we start the service using service mysql start? ESP, is --log-error used?

can't get logging to work on mariadb

I'm trying to get the general logging in mariadb enabled so i can see all the queries being generated against my database.
I'm running version 5.5 on ubuntu:
MariaDB [(none)]> show variables like '%Version';
+------------------+---------------------------------+
| Variable_name | Value |
+------------------+---------------------------------+
| innodb_version | 5.5.43-MariaDB-37.2 |
| protocol_version | 10 |
| version | 5.5.44-MariaDB-1ubuntu0.14.04.1 |
+------------------+---------------------------------+
3 rows in set (0.03 sec)
MariaDB [(none)]>
In my my.cnf file, here's what I've attempted to add in the [mysqld] section:
general-log
general-log-file=queries.log
log-output=file
The reference I was using can be found here: https://mariadb.com/kb/en/mariadb/general-query-log/
When I restart my database using "/etc/init.d/mysql restart", and I start requesting pages via my web application, I can't find any log files being generated eventhough I'm certain the database is being queried.
Any suggestions?
EDIT 1
Upon closer examination, I've noticed that the error log isn't working either.
When I restart mysql, I get the following messages:
myuser#dev:/etc/mysql$ sudo /etc/init.d/mysql restart
* Stopping MariaDB database server mysqld [fail]
* Starting MariaDB database server mysqld [ OK ]
Notice how the stop command fails. But I can't find any error logs.
This is my entire msqld section in my.cnf:
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
general-log
general-log-file=queries.log
log-output=file
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
EDIT 2
Results from "show variables like '%log%'" command is pasted here:
http://pastebin.com/Zt8xFxLN
Line 18 seems to be my problem and maybe line 30 for the error logs?
If i change these values via command line, will it only last for the current session?
Something stood out to me while reading the documentation in your first link:
By adding this to your my.cnf file all queries will be logged to the file queries.log in the datadir directory.
So, I enabled it and had a look at the contents of /var/lib/mysql (the mysql/mariadb datadir).
And there it was - queries.log
The datadir isn't exactly where I'd expect it to be either, but the docs say so. I'd rather see it in /var/log/mysql (it is a log, after all), so I changed the above configuration to a full path (/var/log/mysql/queries.log). The result is as expected, the log ends up in /var/log/mysql
yay!
Seems that things changed since this discussion. As of today, I can enable logging with
mysql -e "SET GLOBAL general_log=1;"
mysql -e "SET GLOBAL general_log_file='all_query.log';"
less +F /var/lib/mysql/all_query.log
Note that the file appears in /var/lib/mysql, rather than in /var/log/mysql ...
I ran the following command on the mysql commandline:
set global log="on"

Mysql max_allowed_packet

I'm having some troubles setting MySql (mariadb running on CentOS7)
When I issue
show global variables where variable_name = 'max_allowed_packet';
The response is
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.00 sec)
Witch means that it is 1M. I need to leave permanently this value at 5M or bigger
I tried editing the file /etc/my.cnf by adding
[mysqldump]
max_allowed_packet=16M
So it remained like this.
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqldump]
max_allowed_packet=16M
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
But after restarting the server it looks like the max_allowed_packet = 1048576
Any suggestion please?.
Thanks in advance.
I finally could solve this particular problem.
We are talking about a droplet in DigitalOcean.
After the doplet creation I just followed a tutorial and issued a "yum install mariadb" (Or may be mariadb-server, not sure).
It seemed to be ignoring all configuration in /etc/my.cnf so I tried a Fedora droplet.
I was able to install MySql from an Oracle YUM repository.
Everything was fine. But I will talk about a problem on Fedora in another question (Or may be submit a ticket).
What I did is to visit mariadb official site and following some instructions i arrived to this page.
https://downloads.mariadb.org/mariadb/repositories/#mirror=edatel&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.0
So setting up the official mariadb resppository and then issuing "yum install mariaDB" seemed to fix the problem.
Thats all for now. Thank you all for reading.