Viewing earlier Query log - MySQL - mysql

I want to see mysql queries [history, log] [select,insert,update,...] [which i executed] !
Can anyone help me on this ?
I'm using MySQL Version : 5.5.8 [which i got from WAMP]
I tried changing settings from console, and failed ! [change gets lost after restart]
i've asked it before, but no working answer !

Sourav's answer no longer works. As of July 2013, you need:
general-log=1
general-log-file = "C:\wamp\logs\mysql_general.log"

Change the following settings in my.ini:
[mysqld]
port=3306
long_query_time = 1
slow_query_log = 1
slow_query_log_file = "E:/wamp/logs/slowquery.log"
log = "E:/wamp/logs/genquery.log"

Related

MySQL / MariaDB: InnoDB: Fatal - how to fix it?

it is friday but no weekend yet. :( My colleague is on vacation and I myself am not a MySQL Pro.
So this morning today our pages stopped working and I am trying to fix for hours now but couldn't solve it myself.
So, baseline error is:
"Status: "InnoDB: Fatal: Trying to access page number 62087 in space 0 space name /var/lib/mysql/db/ibdata1, which is outside the tablespace bounds. Byte offset 0, len 16384 i/o type 10.Please check that the configuration matches the InnoDB system tablespace location (ibdata files)""
I did find a quite similar problem here: https://dba.stackexchange.com/questions/183862/trying-to-solve-outside-tablespace-bounds-mysql-error-but-recovering-table-wi
Sadly there is no solution provided.
The command "mysqldump" from the post above won't work anyway, as the whole service is not starting up.
I recreated the DB status from yesterday using snapper -> that is why I absolutely have no clue why it does not work now. Tried the timestamp from Wednesday - same issue.
Configuration reads:
[mysqld]
datadir=/var/lib/mysql/db
socket=/var/lib/mysql/mysql.sock
innodb_data_home_dir = /var/lib/mysql/db
innodb_data_file_path = ibdata1:10M:autoextend
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# include all files from the config directory
#
!includedir /etc/my.cnf.d
innodb_force_recovery=4
Moving / renaming the original ibdata1 did not solve anything. The thought was that maybe letting the system recreate the file would solve the problem.
Any input on this is highly appreciated.
I do not much care about data loss as long as the service will be running again, which has the highest priority right now.
Thanks a lot
James

MySQL sort_buffer_size

I have received this error:
Bad SQL query Incorrect key file for table '/tmp/#sql_659_0.MYI'; try to repair it
So, following this suggesttion, I try to edit:
sort_buffer_size=4M
join_buffer_size=4M
But I can not find them. Where are they located on Ubuntu 14.04 machine? There are no such options in /etc/mysql/my.cnf
You can run the command find / -name my.cnf on the terminal.This would work as mentioned here
try finding the location of my.cnf as explained here
Secondly i think the title of this question should be:
Where to find my.cnf in Ubuntu 14.04
If you just want to change the values in the running instance you could do (just fire it as a query from anywhere):
SET #FourMegs = 1024 * 1024 * 4;
SET GLOBAL sort_buffer_size = #FourMegs;
SET GLOBAL join_buffer_size = #FourMegs;

MYSQL Slow Query

How can I view mysql slow_query_log to see which query is taking too much time?
First, you need to check if it's enabled in your MySQL configuration (mysql.ini or mysql.cnf, depending on your system):
# enable slow log:
slow_query_log = 1
# log queries longer than n seconds:
long_query_time = 5
# where to log:
slow_query_log_file = /path/to/your/logs/mysql-slow.log
Restart your MySQL server, then watch the logfile using whatever program you like - tail is the simplest:
tail -f /path/to/your/logs/mysql-slow.log
You may need to play a bit with the long_query_time setting to find the limit where the volume of logging isn't too low or too high, but just right.
Check the location of this log in my.ini file, and then open it in any text editor.
if you ask google for "slow_query_log", this is the first hit - explaining all you need to know. you have to enable it, set a filename you like (if it's already set, you can find the configuration in you my.ini), start your queries and look ito that file...
If you're running mysqld < 5.2, your my.cnf may look like
log-slow-queries=/var/log/mysql/mysql-slow.log //where to store log
long_query_time=3 //quickest query to log

How can I enable MySQL's slow query log without restarting MySQL?

I followed the instructions here: http://crazytoon.com/2007/07/23/mysql-changing-runtime-variables-with-out-restarting-mysql-server/ but that seems to only set the threshold.
Do I need to do anything else like set the filepath?
According to MySQL's docs
If no file_name value is given for --log-slow-queries, the default name is
host_name-slow.log. The server creates the file in the data directory unless
an absolute path name is given to specify a different directory.
Running
SHOW VARIABLES
doesn't indicate any log file path and I don't see any slow query log file on my server...
EDIT
Looks like I'm using server version 5.0.77, so I needed to do:
SET GLOBAL log_slow_queries = 1;
but I get: ERROR 1238 (HY000): Variable 'log_slow_queries' is a read only variable
I assume I'm going to need to restart the server and have log_slow_queries set in my config?
Try SET GLOBAL slow_query_log = 'ON'; and perhaps FLUSH LOGS;
This assumes you are using MySQL 5.1 or later. If you are using an earlier version, you'll need to restart the server. This is documented in the MySQL Manual. You can configure the log either in the config file or on the command line.
For slow queries on version < 5.1, the following configuration worked for me:
log_slow_queries=/var/log/mysql/slow-query.log
long_query_time=20
log_queries_not_using_indexes=YES
Also note to place it under [mysqld] part of the config file and restart mysqld.
Find log enabled or not?
SHOW VARIABLES LIKE '%log%';
Set the logs:-
SET GLOBAL general_log = 'ON';
SET GLOBAL slow_query_log = 'ON';
MySQL Manual - slow-query-log-file
This claims that you can run the following to set the slow-log file (5.1.6 onwards):
set global slow_query_log_file = 'path';
The variable slow_query_log just controls whether it is enabled or not.
I think the problem is making sure that MySQL server has the rights to the file and can edit it.
If you can get it to have access to the file, then you can try setting:
SET GLOBAL slow_query_log = 1;
If not, you can always 'reload' the server after changing the configuration file. On linux its usually /etc/init.d/mysql reload
These work
SET GLOBAL LOG_SLOW_TIME = 1;
SET GLOBAL LOG_QUERIES_NOT_USING_INDEXES = ON;
Broken on my setup 5.1.42
SET GLOBAL LOG_SLOW_QUERIES = ON;
SET GLOBAL SLOW_QUERY_LOG = ON;
set ##global.log_slow_queries=1;
http://bugs.mysql.com/bug.php?id=32565
Looks like the best way to do this is set log_slow_time very high thus "turning off" the slow query log. Lower log_slow_time to enable it. Use the same trick (set to OFF) for log_queries_not_using_indexes.
If you want to enable general error logs and slow query error log in the table instead of file
To start logging in table instead of file:
set global log_output = “TABLE”;
To enable general and slow query log:
set global general_log = 1;
set global slow_query_log = 1;
To view the logs:
select * from mysql.slow_log;
select * from mysql.general_log;
For more details visit this link
http://easysolutionweb.com/technology/mysql-server-logs/
This should work on mysql > 5.5
SHOW VARIABLES LIKE '%long%';
SET GLOBAL long_query_time = 1;

Getting MySQL to work on CentOs 5

I've bee tearing my hair out trying to get MySQL 5 running on CentOS 5 but I've had hardly any luck.
If I leave everything as default, and launch the initial install it works a charm, but if I tell the my.cnf to use a different drive to store the data, I continuously get the "Timeout error occurred trying to start MySQL Daemon." error.
My.cnf is as follows:
[mysqld]
datadir=/database/mysql
socket=/database/mysql/mysql.sock
user=mysql
old_passwords=1
log-error=/database/log/mysqld.log
long_query_time = 10
log_slow_queries = /database/log/mysql-slow.log
query-cache-type = 1
query-cache-size = 8M
innodb_file_per_table
skip-bdb
set-variable = local-infile=0
[mysqld_safe]
pid-file=/var/run/mysqld/mysqld.pid
The folders all have the right privileges and the mysqld.log doesn't have any error messages in there, according to it, MySQL launced successfuly.
Oh, and /database is a mounted drive, but even if I trial it on a local directory, I get the same error.
Any ideas what could be going wrong? i've seriously waisted more than 5 hours on this now :(
CHEERS
Shouldn't the datadir be set to the other drive and everything else (socket) point to the standard install locations?
Did you check selinux settings? Make sure it is disabled (setenforce disabled), or spent some time learn about it (chcon command) To disable on boot look into /etc/sysconfig
Run the command : getenforce, if it says "Enforced", SE-Linux is On