I need to turn this on/enable it. I found some info on the net but am very confused now, I don't know where to start.
This is what I have so far. I logged onto MySQL as root and did:
show variables like '%log%';
and got:
Variable_name | Value |
+---------------------------------+----------------------------------+
| back_log | 50 |
| binlog_cache_size | 32768 |
| binlog_format | STATEMENT |
| expire_logs_days | 10 |
| general_log | ON |
| general_log_file | /var/lib/mysql/helloise.log |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_buffer_size | 1048576 |
| innodb_log_file_size | 5242880 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | ./ |
| innodb_mirrored_log_groups | 1 |
| log | ON |
| log_bin | OFF |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| log_error | /var/log/mysql/error.log |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | OFF |
| log_slow_queries | OFF |
| log_warnings | 1 |
| max_binlog_cache_size | 4294963200 |
| max_binlog_size | 104857600 |
| max_relay_log_size | 0 |
| relay_log | |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_purge | ON |
| relay_log_space_limit | 0 |
| slow_query_log | OFF |
| slow_query_log_file | /var/lib/mysql/helloise-slow.log |
| sql_log_bin | ON |
| sql_log_off | OFF |
| sql_log_update | ON |
| sync_binlog | 0
I did: SET GLOBAL general_log = 1 to set general_log = ON. Will all queries be logged in /var/lib/mysql/helloise.log?
And when I try to access the mysql directory via helloises#helloise:/var/lib$ cd mysql/ I get permission denied
and then I also have a log directory:
helloises#helloise:/var/log$
with a whole lot of log files ex: mysql.log
Which log file will contain my queries so I can track what my db is doing and see how long queries take?
Firs of all you got a permission denied because you hav not the privileges to read it. Try a
ls -l
on that file and see what permission are defined. Then yuo can use chmod to change permissions. Or simply try to read that file as a root user.
The general log is a logging feature for query log, reading, from guide:
The general query log is a general record of what mysqld is doing. The
server writes information to this log when clients connect or
disconnect, and it logs each SQL statement received from clients. The
general query log can be very useful when you suspect an error in a
client and want to know exactly what the client sent to mysqld.
The error log:
The error log contains information indicating when mysqld was started
and stopped and also any critical errors that occur while the server
is running. If mysqld notices a table that needs to be automatically
checked or repaired, it writes a message to the error log.
For understand the differences i suggest you to read that site:
http://dev.mysql.com/doc/refman/5.1/en/server-logs.html
The file that contains the queries is the one in /var/lib/mysql/helloise.log
For the slow query logs you can check:
http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html
it logs all the query that take more time than long_query_time seconds (that variable must be defined by yourself). I don't found a way to show the execution time of a query, but check that page http://dev.mysql.com/doc/refman/5.1/en/log-destinations.html it could help you on how to configure general/slowquery logging.
Hope this help.
Related
So i have this mysql innodb cluster of 3 mysql instances on docker that is always failing with the error group replication not active.
Looking at the error logs, the only thing i can find is this warning:
Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=f3353ca0124a-relay-bin' to avoid this problem
I try the following query on the particular mysql instance 'f3353ca0124a'
show variables like '%relay_log%';
and i find
+---------------------------+---------------------------------------------+
| Variable_name | Value |
+---------------------------+---------------------------------------------+
| max_relay_log_size | 0 |
| relay_log | f3353ca0124a-relay-bin |
| relay_log_basename | /var/lib/mysql/f3353ca0124a-relay-bin |
| relay_log_index | /var/lib/mysql/f3353ca0124a-relay-bin.index |
| relay_log_info_file | relay-log.info |
| relay_log_info_repository | TABLE |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| sync_relay_log | 10000 |
| sync_relay_log_info | 10000 |
+---------------------------+---------------------------------------------+
11 rows in set (0.11 sec)
So i am confused cos it looks to me that the value which the error suggest i should set is already set.
Please can anyone help show me how to fix this error.
I am trying to debug why my DML statements aren't ending up in the binlogs. The master and slave appear to be talking to eachother and the slave status indicates that it caught up properly to the most recent log file.
I did a show variables LIKE '%binlog%'; with this output, but binlog_do_db is not there.
+-----------------------------------------+----------------------+
| Variable_name | Value |
+-----------------------------------------+----------------------+
| binlog_cache_size | 32768 |
| binlog_checksum | CRC32 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| innodb_api_enable_binlog | OFF |
| innodb_locks_unsafe_for_binlog | OFF |
| log_statements_unsafe_for_binlog | ON |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_size | 104857600 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| sync_binlog | 1 |
+-----------------------------------------+----------------------+
After much effort and grief, I found that in the previous administrator must have been trying to get replication to work and put these lines into the /etc/mysql/mysql.conf.d/mysqld.cnf file
# Setup Incremental Backups
log-bin = /srv/ddisk/backups/mysql/mysql_inc
expire_logs_days = 3
max_binlog_size = 100M
server-id = 1
binlog_do_db = include_database_name
The last line is probably the culprit (though I will likely clean out that whole config block since I have them in the my.cnf config file already. In any case, I am now trying to verify that this configuration is actually being read by MySQL, but I'm unable to figure out what query to run to find this variable.
Would someone happen to know how to find binlog_do_db?
Thanks ahead of time
You can check using mysql prompt on the master node below:
mysql> SHOW MASTER STATUS;
It will show Binary log file, position, Binlog_Do_DB, Binlog_Ignore_DB parameter and so on.
I have a large amount of connections but when I issue a show full processlist I am not showing anything close to the connections I see. Are these connections orphans of some sort? I tried the flush hosts command and the connections persist, even with a reboot of the server and also restarting the mysql server.
I believe these connections are causing issues with making new connections to the database. User's are getting a "server went away" error. How do I clear these?
See commands below:
mysql> show status like '%onn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 5 |
| Connections | 11743 |
| Max_used_connections | 24 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 6 |
+--------------------------+-------+
7 rows in set (0.00 sec)
mysql> show full processlist;
+-------+---------+----------------------+--------------------+---------+-------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+---------+----------------------+--------------------+---------+-------+-------+-----------------------+
| 4494 | rode | localhost:43411 | NULL | Sleep | 11159 | | NULL |
| 4506 | rode | localhost:43423 | information_schema | Sleep | 11159 | | NULL |
| 4554 | rode | localhost:43511 | performance_schema | Sleep | 11112 | | NULL |
| 11500 | ass | serv:1243 | Home-Tech | Sleep | 0 | | NULL |
| 11743 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
| 11744 | ass | out:6070 | Home-Tech | Sleep | 4 | | NULL |
| 11745 | ass | out:6074 | HTGlobal | Sleep | 8 | | NULL
The MySQL server has gone away (error 2006) has two main causes
Server timed out and closed the connection. To fix, check that “wait_timeout” mysql variable in your my.cnf configuration file is large enough.
Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. To fix, you can increase the maximal packet size limit “max_allowed_packet” in my.cnf file, eg. set max_allowed_packet = 128M, then sudo /etc/init.d/mysql restart.
there are two main ways to fix this. if the above change doesn't there may be an issue with your linux or windows mysql database server; you either need to increase ram on your server or watch it's process.
is this on a windows or linux box?
I want to check the log in MySQL to see the queries that are being run by my application. How can I do this? I am using XAMPP and the directory to MySQL is C:\xampp\mysql.
This is what I get when I do show variables like '%log%';
mysql> show variables like '%log%';
+---------------------------------+------------------------------------+
| Variable_name | Value |
+---------------------------------+------------------------------------+
| back_log | 50 |
| binlog_cache_size | 32768 |
| binlog_format | STATEMENT |
| expire_logs_days | 0 |
| general_log | OFF |
| general_log_file | C:/xampp/mysql/data/mysql.log |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_buffer_size | 8388608 |
| innodb_log_file_size | 5242880 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | C:\xampp\mysql\data\ |
| innodb_mirrored_log_groups | 1 |
| log | OFF |
| log_bin | OFF |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| log_error | C:\xampp\mysql\data\mysql.err |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | OFF |
| log_slow_queries | OFF |
| log_warnings | 1 |
| max_binlog_cache_size | 4294963200 |
| max_binlog_size | 1073741824 |
| max_relay_log_size | 0 |
| relay_log | |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_purge | ON |
| relay_log_space_limit | 0 |
| slow_query_log | OFF |
| slow_query_log_file | C:/xampp/mysql/data/mysql-slow.log |
| sql_log_bin | ON |
| sql_log_off | OFF |
| sql_log_update | ON |
| sync_binlog | 0 |
+---------------------------------+------------------------------------+
37 rows in set (0.00 sec)
Enable general query log by the following query in mysql command line
SET GLOBAL general_log = 'ON';
Now open C:/xampp/mysql/data/mysql.log and check query log
If it fails, open your my.cnf file. For windows its my.ini file and enable it there. Just make sure its in the [mysqld] section
[mysqld]
general_log = 1
Note: In xampp my.ini file can be either found in xampp\mysql or in c:\windows directory
Set up the General Query Log.
Its given on OFFICIAL MYSQL website.
SET GLOBAL general_log = 'ON';
You can also use custom path:
[mysqld]
# Set Slow Query Log
long_query_time = 1
slow_query_log = 1
slow_query_log_file = "C:/slowquery.log"
#Set General Log
log = "C:/genquery.log"
Seems like the general query log is the file that you need. A good introduction to this is at http://dev.mysql.com/doc/refman/5.1/en/query-log.html
For me, general_log didn't worked. But adding this to my.ini worked
[mysqld]
log-output=FILE
slow_query_log = 1
slow_query_log_file = "d:/temp/developer.log"
How can I enable the General Log for MySQL for use with MAMP?
I use it to run Apache, MySQL and PHP on my Mac so I can turn on/off/restart via a UI instead of messing with Apache or PHP that's installed in the machine by default.
On my Mac, I've tried setting config settings in the my.cnf file to log every SQL query that's run to a file. The setting seems to have taken affect as shown by the output below when I run the SHOW VARIABLES command from within Terminal.
Problem: General Log file isn't bring populated.
When I actually execute an SQL query or reload a PHP page on the MAMP server that reads data from the MySQL database, the general log file isn't created or populated.
Here's the part of content of my.cnf that I have set:
# The MySQL server
[mysqld]
#port = 9999
socket = /Applications/MAMP/tmp/mysql/mysql.sock
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
bind-address = 127.0.0.1
general_log = 1
general_log_file = /Applications/MAMP/logs/mysql_general_sql.log
Here's part of the output from running SHOW VARIABLES statement:
mysql> show variables;
+---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------+
| ... | ... |
| general_log | ON |
| general_log_file | /Applications/MAMP/logs/mysql_general_sql.log |
| log | ON |
| log_bin | OFF |
| log_bin_trust_function_creators | OFF |
| log_error | /Applications/MAMP/logs/mysql_error_log.err |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | OFF |
| log_slow_queries | OFF |
| log_warnings | 1 |
| long_query_time | 10.000000 |
| relay_log | |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| report_host | |
| report_password | |
| report_port | 3306 |
| report_user | |
| server_id | 1 |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /Library/Application Support/appsolute/MAMP PRO/db/mysql/tim-slow.log |
| socket | /Applications/MAMP/tmp/mysql/mysql.sock |
| sql_log_bin | ON |
| sql_log_off | OFF |
| ... | ... |
+---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------+
318 rows in set (0.01 sec)
Is there something I'm missing?
I tried running the command SET GLOBAL general_log = 'ON'; to see if I could get it to work that way. This produced an error message File Not Found, even though the file did exist.
This indicated to me that problem may be due to file permissions.
After some playing around, I changed:
the owner of the file to match the user that the MySQL service was being run under, and
gave that user "write access" to the file
Since making those changes, it's been working perfectly ever since.