When launching mysqlbinlog it returns an error:
root#utils # mysqlbinlog --start-datetime="2021-12-05 13:13:00"
mysqlbinlog: unknown variable 'default-character-set=utf8mb4'
How to fix it?
Maybe, it related to the contents of /etc/mysql/mariadb.conf.d/50-client.cnf which is:
[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
default-character-set = utf8mb4
# socket location
socket = /var/run/mysqld/mysqld.sock
# Example of client certificate usage
# ssl-cert=/etc/mysql/client-cert.pem
# ssl-key=/etc/mysql/client-key.pem
#
# Allow only TLS encrypted connections
# ssl-verify-server-cert=on
# This group is *never* read by mysql client library, though this
# /etc/mysql/mariadb.cnf.d/client.cnf file is not read by Oracle MySQL
# client anyway.
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]
The server configuration is:
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1-log Ubuntu 20.04
character-set-server = utf8mb4
or
mysqlbinlog --no-defaults mysql-bin.000001
Another solution is to add the loose_ prefix to the failing option:
[client]
loose-default-character-set=utf8mb4
The loose prefix forces command line tools not to throw an error, if the option isn't supported.
Move the default-character-set=utf8 line below the [mysql] or [mysqld]
sections of your my.cnf file. mysqlbinlog reads variables under
[client], but not [mysql]. Your command-line client and/or browser
reads the [client] AND [mysql] sections of the config file.
BTW, mysqlbinlog can take a specified character set, if you use the
--set-charset=charset_name (>5.0.23) option.
source: https://forums.mysql.com/read.php?103,189835,192421#msg-192421
I'm installing new software on a new Ubuntu 16.0.4 machine and installed MySQL with apt-get. The version I get is 5.7.22 but can't get it to accept
my settings of the configuration variable lower_case_table_names.
I'm adding lines like:
[mysql]
lower_case_table_names = 1
When I edit any of the *.cnf files in /etc/mysql to have this setting or if I add it to ~/.my.cnf I get
mysql: [ERROR] unknown variable 'lower_case_table_names=1'
if I try to start mysql. Similarly I can't use it on the mysql command line like the doc says I can.
/usr/bin/mysql --lower_case_table_names=1 -u root -p
However:
If I go into the SQL command interpreter and type
mysql> select ##lower_case_table_names;
I get back a result showing the variable is set to 0. However it cannot be changed with a SET statement...
So whats the deal with why I can't set this variable ?
~/.my.cnf file:
[mysqld]
lower_case_table_names = 1
[mysql]
lower_case_table_names = 1
Why is mysql not liking this variable name when clearly it still has a setting for it?
The problem is that this variable does not apply to mysql. It only applies
to mysqld. Stop mysqld, change the my.cnf to have a setting for [mysqld], and then start mysqld. This will set the lower_case_table_names value for the mysql server.
If you run /usr/bin/mysql (a command line mysql shell) it will not want a setting for this var in the config file. The shell will behave as the mysql server behaves.
Help requested on 'mysqldump' error
I'm in the hell figuring out why following error happens. So, please, anybody help me. My writing: A, B, C, D
s
A. Here is my.ini file
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = C:\mysql-5.6.27
datadir = C:\mysql-5.6.27\data
port = 3306
max_allowed_packet=16M
character-set-client-handshake = false
init_connect="SET collation_connection=utf8_general_ci"
init_connect="SET NAMES utf8"
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
default-character-set=utf8
#bind-address = 0.0.0.0
#explicit_defaults_for_timestamp=1
[mysql]
default-character-set = utf8
[mysqldump]
#sql_mode=NO_AUTO_VALUE_ON_ZERO
========================== end of ini file
B. I executed the following command ==>
C:\mysql-5.6.27\bin> mysqldump -uroot -p --databases parkinglot > prugio.sql
C. Here is the response on my mysqldump
mysqldump: unknown variable 'sql+mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'
D. For your reference, I upgraded mysql version from 5.6.24 to 5.6.27.
Thank you very much in advance.
I just found answer myself. I had my.ini in two plases. one in C drive and the other one in D drive. That caused the confusion. As soon as I renamed one of the my.ini, the problem didn't happen.
I've read that Mysql server creates a log file where it keeps a record of all activities - like when and what queries execute.
Can anybody tell me where it exists in my system? How can I read it?
Basically, I need to back up the database with different input [backup between two dates] so I think I need to use log file here, that's why I want to do it...
I think this log must be secured somehow because sensitive information such as usernames and password may be logged [if any query require this]; so may it be secured, not easily able to be seen?
I have root access to the system, how can I see the log?
When I try to open /var/log/mysql.log it is empty.
This is my config file:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
log = /var/log/mysql/mysql.log
binlog-do-db=zero
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
general_log_file = /var/log/mysql/mysql.log
general_log = 1
Here is a simple way to enable them. In mysql we need to see often 3 logs which are mostly needed during any project development.
The Error Log. It contains information about errors that occur while
the server is running (also server start and stop)
The General Query Log. This is a general record of what mysqld is
doing (connect, disconnect, queries)
The Slow Query Log. Ιt consists of "slow" SQL statements (as
indicated by its name).
By default no log files are enabled in MYSQL. All errors will be shown in the syslog (/var/log/syslog).
To Enable them just follow below steps:
step1: Go to this file (/etc/mysql/conf.d/mysqld_safe_syslog.cnf) and remove or comment those line.
step2: Go to mysql conf file (/etc/mysql/my.cnf) and add following lines
To enable error log add following
[mysqld_safe]
log_error=/var/log/mysql/mysql_error.log
[mysqld]
log_error=/var/log/mysql/mysql_error.log
To enable general query log add following
general_log_file = /var/log/mysql/mysql.log
general_log = 1
To enable Slow Query Log add following
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
step3: save the file and restart mysql using following commands
service mysql restart
To enable logs at runtime, login to mysql client (mysql -u root -p) and give:
SET GLOBAL general_log = 'ON';
SET GLOBAL slow_query_log = 'ON';
Finally one thing I would like to mention here is I read this from a blog. Thanks. It works for me.
Click here to visit the blog
The MySQL logs are determined by the global variables such as:
log_error for the error message log;
general_log_file for the general query log file (if enabled by general_log);
slow_query_log_file for the slow query log file (if enabled by slow_query_log);
To see the settings and their location, run this shell command:
mysql -se "SHOW VARIABLES" | grep -e log_error -e general_log -e slow_query_log
To print the value of error log, run this command in the terminal:
mysql -e "SELECT ##GLOBAL.log_error"
To read content of the error log file in real time, run:
sudo tail -f $(mysql -Nse "SELECT ##GLOBAL.log_error")
Note: Hit Control-C when finish
When general log is enabled, try:
sudo tail -f $(mysql -Nse "SELECT CONCAT(##datadir, ##general_log_file)")
To use mysql with the password access, add -p or -pMYPASS parameter. To to keep it remembered, you can configure it in your ~/.my.cnf, e.g.
[client]
user=root
password=root
So it'll be remembered for the next time.
You have to activate the query logging in mysql.
edit /etc/my.cnf
[mysqld]
log=/tmp/mysql.log
restart the computer or the mysqld service
service mysqld restart
open phpmyadmin/any application that uses mysql/mysql console and run a query
cat /tmp/mysql.log ( you should see the query )
From the MySQL reference manual:
By default, all log files are created in the data directory.
Check /var/lib/mysql folder.
In my (I have LAMP installed) /etc/mysql/my.cnf file I found following, commented lines in [mysqld] section:
general_log_file = /var/log/mysql/mysql.log
general_log = 1
I had to open this file as superuser, with terminal:
sudo geany /etc/mysql/my.cnf
(I prefer to use Geany instead of gedit or VI, it doesn't matter)
I just uncommented them & save the file then restart MySQL with
sudo service MySQL restart
Run several queries, open the above file (/var/log/mysql/mysql.log) and the log was there :)
Enter MySQL/MariaDB server command-line tool as root
Set file path (you can replace general.log with the file name of your choice).
SET GLOBAL general_log_file='/var/log/mysql/general.log';
Set log file format
SET GLOBAL log_output = 'FILE';
Enable the server general log
SET GLOBAL general_log = 'ON';
Check your configurations in global configuration variables.
SHOW VARIABLES LIKE "general_log%";
Enter exit to leave MySQL command-line and Tail your queries by
tail -f /var/log/mysql/general.log
or
less /var/log/mysql/general.log
To disable the general server log
SET GLOBAL general_log = 'OFF';
To complement loyola's answer it is worth mentioning that as of MySQL 5.1 log_slow_queries is deprecated and is replaced with slow-query-log
Using log_slow_queries will cause your service mysql restart or service mysql start to fail
In addition to the answers above you can pass in command line parameters to the mysqld process for logging options instead of manually editing your conf file. For example, to enable general logging and specifiy a file:
mysqld --general-log --general-log-file=/var/log/mysql.general.log
Confirming other answers above, mysqld --help --verbose gives you the values from the conf file (so running with command line options general-log is FALSE); whereas mysql -se "SHOW VARIABLES" | grep -e log_error -e general_log gives:
general_log ON
general_log_file /var/log/mysql.general.log
Use slightly more compact syntax for the error log:
mysqld --general-log --general-log-file=/var/log/mysql.general.log --log-error=/var/log/mysql.error.log
shell> mysqladmin flush-logs
shell> mv host_name.err-old backup-directory
I am trying to set sql_mode in MySQL but it throws an error.
Command:
set global sql_mode='NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLE','NO_AUTO_CREATE_USER','NO_ENGINE_SUBSTITUTION'
Is this not the proper way to set multiple modes?
What are the advantages of setting session and global modes?
Which is preferred?
I have different users trying to update the database with different UNC values and instead of setting the session mode to NO_BACKSLASH_ESCAPES, I though it would make sense to set a global mode for this. Does this make sense?
Please let me know.
Thanks.
BTW, if you set globals in MySQL:
SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';
This will not set it PERMANENTLY, and it will revert after every restart.
So you should set this in your config file (e.g. /etc/mysql/my.cnf in the [mysqld] section), so that the changes remain in effect after MySQL restart:
Config File: /etc/mysql/my.cnf
[mysqld]
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
UPDATE: Newer versions of Mysql (e.g. 5.7.8 or above) may require slightly different syntax:
[mysqld]
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
Make sure that there is a dash between sql-mode not an underscore, and that modes are in double quotes.
Always reference the MySQL Docs for your version to see the sql-mode options.
I resolved it.
the correct mode is :
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Setting sql mode permanently using mysql config file.
In my case i have to change file /etc/mysql/mysql.conf.d/mysqld.cnf as mysql.conf.d is included in /etc/mysql/my.cnf. i change this under [mysqld]
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
just removed ONLY_FULL_GROUP_BY sql mode cause it was causing issue.
I am using ubuntu 16.04, php 7 and mysql --version give me this mysql Ver 14.14 Distrib 5.7.13, for Linux (x86_64) using EditLine wrapper
After this change run below commands
sudo service mysql stop
sudo service mysql start
Now check sql modes by this query SELECT ##sql_mode and you should get modes that you have just set.
For someone who googling this error for MySQL 8.
MySQL 8.0.11 remove the 'NO_AUTO_CREATE_USER' from sql-mode.
MySQL 5.7: Using GRANT to create users. Instead, use CREATE USER.
Following this practice makes the NO_AUTO_CREATE_USER SQL mode
immaterial for GRANT statements, so it too is deprecated. MySQL
8.0.11: Using GRANT to create users. Instead, use CREATE USER. Following this practice makes the NO_AUTO_CREATE_USER SQL mode
immaterial for GRANT statements, so it too is removed.
Taken from here
So, your sql_mode can be like this:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
Or if you're using Docker you can add next command to docker-compose.yml
mysql:
image: mysql:8.0.13
command: --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
ports:
- 13306:${MYSQL_PORT}
Copy to Config File: /etc/mysql/my.cnf OR /bin/mysql/my.ini
[mysqld]
port = 3306
sql-mode=""
MySQL restart.
Or you can also do
[mysqld]
port = 3306
SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
MySQL restart.
Access the database as the administrator user (root maybe).
Check current SQL_mode
mysql> SELECT ##sql_mode;
To set a new sql_mode, exit the database, create a file
nano /etc/mysql/conf.d/<filename>.cnf
with your sql_mode content
[mysqld]
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Restart Mysql
mysql> sudo service mysql stop
mysql> sudo service mysql start
We create a file in the folder /etc/mysql/conf.d/
because in the main config file /etc/mysql/my.cnf
the command is written to include all the settings files from the folder /etc/mysql/conf.d/
For Temporary change use following command
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
For permanent change : go to config file /etc/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf and add following lines then restart mysql service
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Check the documentation of sql_mode
Method 1:
Check default value of sql_mode:
SELECT ##sql_mode //check current value for sql_mode
SET GLOBAL sql_mode = "NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
Method 2:
Access phpmyadmin for editing your sql_mode
Login on phpmyadmin and open localhost
Top on Variables present on the top in menu items and search out for sql mode
Click on edit button to modify sql_mode based on your requirements
Save the changes
Restart server after executing above things
In my case mysql and ubuntu 18.04
I set it permanently using this command
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Append the line after the configuration. See example highlighted in the image below.
sql_mode = ""
Note :You can also add different modes here, it depends on your need
NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
See Available sql modes reference and Documentation
Then save.
After saving you need to restart your mysql service, follow the command below:
sudo service mysql restart
Hope this helps :-)
In my case i have to change file /etc/mysql/mysql.conf.d/mysqld.cnf change this under [mysqld]
Paste this line on [mysqld] portion
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
I just had a similar problem where MySQL (5.6.45) wouldn't accept sql_mode from any config file.
The solution was to add init_file = /etc/mysql/mysql-init.sql to the config file and then execute SET GLOBAL sql_mode = ''; in there.
If someone want to set it only for the current session then use the following command
set session sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Updating this for users Using MAMP PRO {works with MAMP users too}. Because I seem to have got stuck on finding a solution for this, but people recommended I should edit the my.cnf file in the /Applications/MAMP/tmp/mysql/my.cnf folder which does not work because it gets reset after every restart of mysql server.
Referring this document:
The configuration file “my.cnf” of MySQL can be found here:
“/Applications/MAMP/tmp/mysql/my.cnf”. Please note: Editing this file
does NOT work as it will be overwritten every time MySQL is restarted
by MAMP PRO with a “my.cnf” file that is created from the MySQL
template. You must edit this template (menu File > Open Template >
MySQL (my.cnf) > 5.7.30) to modify the MySQL configuration. Manually
adding “my.cnf” files to other locations is not recommended. Every
configuration aspect can be handled with the MySQL template.
Once this is done, add the following in the my.cnf file:
[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Restart the Mysql Server. That should do the trick.
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"