Difficulty changing max_allowed_packet in mysql - mysql

I am trying to change the max_allowed_packet=20M. This is that I've done:
$ mysql -u root -e 'show variables like "max%"'
+----------------------------+----------------------+
| Variable_name | Value |
+----------------------------+----------------------+
| max_allowed_packet | 16777216 |
$ sudo vim /etc/my.cnf
# my.cnf
[mysqld]
max_allowed_packet=20M
$ sudo service mysql restart
$ mysql -u root -e 'show variables like "max%"'
+----------------------------+----------------------+
| Variable_name | Value |
+----------------------------+----------------------+
| max_allowed_packet | 16777216 |
Why is nothing changing here? What do I need to do to actually change this setting? (Note that I am using ec2 here).

Try
[mysqld]
max-allowed-packet=20M
instead.
Computer can be SO picky!

Your restart query is incorrect. It should be:
$ sudo service mysqld restart
You missed "d" in mysqld

Related

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

Change MySQL /tmp to /somedrive/mysqltmp in centos 7 for error code 28

I am trying to change the temp location for MySQL from default /tmp to /somedrive/mysqltmp as i am getting
Errcode: 28 - No space left on device
Solution: 1
I tried to add a line in /etc/my.cnf as tmpdir=/somedrive/mysqltmp
then issued sudo service mysql stop and sudo service mysql start
After restart, i still see ERROR remains.
Solution: 2
Based on this I tried
mysqld --verbose --help | grep tmp
tmp-table-size 16777216
tmpdir /tmp
and then i tried
mysqld --tmpdir=/somedrive/mysqltmp
to change the defaults. But i am not able to change the tmp directory. I am not sure what i am missing!
I figured this out: Do changes under
[mysqld] as
tmpdir=/somedrive/mysqltmp
and then issue sudo service mysql stop and sudo service mysql start
Now check:
mysqld --verbose --help | grep tmp
tmp-table-size 16777216
tmpdir /somedrive/mysqltmp
This has happened to me before because mysql was using a my.cnf in a different location. Search for another my.cnf. You could also try moving the my.cnf file that you know of and see if mysql complains.
Do changes under
[mysqld] as
tmpdir=/somedrive/mysqltmp
and then issue sudo service mysql stop and sudo service mysql start
Now check:
mysqld --verbose --help | grep tmp
tmp-table-size 16777216
tmpdir /somedrive/mysqltmp

Mariadb configuration is not loaded from my.cnf

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.

Docker container with MySQL not writing in the log file

I am working on an existing Dockerfile that I have been asked to modify as less as possible. The docker image is based on a CentOS Linux image and is supposed to contain a MySQL service.
I want to enable the verbose logging for all the queries (i.e. general_log and general_log_file variables on the /etc/my.cnf file).
The MySQL service needs to be run in the mysqld_safe mode and I've checked that the configuration lines I am adding (see below the printf) are after the [mysqld_safe] line in the /etc/my.cnf file, so I am assuming this setting should be fine.
What I've done so far is adding to the Dockerfile the following statements:
RUN groupadd -r mysql && useradd -r -g mysql mysql
# [...] Lots of Mysql stuff regarding importing DBs etc.
# Adding some more configuration details to the database service
RUN printf '\n%s\n%s\n%s\n\n' '# Set General Log to log all the queries' 'general_log=1' 'general_log_file=/var/log/mysql_general.log' >> /etc/my.cnf
# Getting the new log file prepared to get written by the MySQL service
RUN touch /var/log/mysql_general.log
RUN chown mysql.mysql /var/log/mysql_general.log
# MySQL Port
EXPOSE 3306
ENTRYPOINT ["mysqld_safe"]
After building the docker image and running the docker container I see this in the /var/log folder:
-rw-r-----. 1 mysql mysql 5108 Nov 20 17:07 mysqld.log
-rw-r--r--. 1 mysql mysql 3880 Nov 20 17:44 mysql_general.log
If I grep the mysqld.log for keywords like ERROR or general I can not find anything interesting. The mysql_general.log file is empty.
I see this also this:
mysql> show variables like '%general_log%';
+------------------+----------------------------+
| Variable_name | Value |
+------------------+----------------------------+
| general_log | OFF |
| general_log_file | /var/run/mysqld/mysqld.log |
+------------------+----------------------------+
2 rows in set (0.00 sec)
mysql>
I am not able to get the SQL queries written in the log file, why?

How to determine which my.cnf mysql is using

Is there a way I can figure out which my.cnf mysql is currently using? The reason is because it's using the correct socket file to connect, but I can't figure out exactly which (if any) my.cnf it's using or trying to use so I can manually set the correct path on my local machine.
$ strace -f -e trace=open mysql 2>&1 | grep $SEARCH_STRING
where usually SEARCH_STRING='cnf' or SEARCH_STRING='ini'
The default extentions for the mysql configuration file are '.cnf' and '.ini' (see http://dev.mysql.com/doc/refman/5.1/en/option-files.html)
A bit hackish:
$ strace mysql 2>&1 | grep 'open' | grep '.cnf'
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
open("/home/reto/.my.cnf", O_RDONLY|O_LARGEFILE) = 3