Cant get general log to show queries in mysql - mysql

Not sure what's going on here, as far as I know everything is set as it's supposed to be but the log stays empty:
[root#myLaptop Me]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
log=/var/log/mysqld.general.log
general_log_file=/var/log/mysqld.general.log
pid-file=/var/run/mysqld/mysqld.pid
[root#myLaptop Me]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
[root#myLaptop Me]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root#myLaptop Me]# mysql -u root -p
Enter password:
... Welcome stuff
Server version: 5.5.30 MySQL Community Server (GPL)
mysql> SET GLOBAL log_output = "FILE";SET GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.05 sec)
mysql> SHOW PROCESSLIST;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 3 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
+----+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)
mysql> quit
Bye
[root#myLaptop Me]# tail /var/log/mysqld.general.log
[root#myLaptop Me]# <= shows nothing at all
[root#myLaptop Me]# ls -l /var/log/mysqld.general.log
-rw-r--r--. 1 mysql mysql 0 May 31 10:06 /var/log/mysqld.general.log
[root#myLaptop Me]# tail /var/log/mysqld.log
130531 10:28:04 InnoDB: Completed initialization of buffer pool
130531 10:28:04 InnoDB: highest supported file format is Barracuda.
130531 10:28:04 InnoDB: Waiting for the background threads to start
130531 10:28:05 InnoDB: 5.5.30 started; log sequence number 2969208
130531 10:28:05 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130531 10:28:05 [Note] - '0.0.0.0' resolves to '0.0.0.0';
130531 10:28:05 [Note] Server socket created on IP: '0.0.0.0'.
130531 10:28:05 [Note] Event Scheduler: Loaded 0 events
130531 10:28:05 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.30' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
[update]
I think fedora 17 starts mysql with parameters that override the my.cnf the log is not where the my.cnf tells it to be:
[root#Laptop Symfony]# mysql -u root -p
mysql> select ##global.general_log_file;
+----------------------------+
| ##global.general_log_file |
+----------------------------+
| /var/lib/mysql/Laptop.log |
+----------------------------+

First, I would check the logging options
please see the logging options from IBM MySQL reference
On my servers, I always create a new directory in /var/log and "give" it to mysql (to be executed as root or via sudo)
sudo mkdir /var/log/mysql
sudo chown mysql:mysql /var/log/mysql
then all logging options from my.cnf are a file inside that directory
log=/var/log/mysql/general.log
log-error=/var/log/mysql/error.log
log-slow-queries=/var/log/mysql/slowquery.log
to be sure in any case, mysql can create and access the files. Moreover, it helps to visit all the mysql log files at once, since the /var/log directory is pretty busy with many things not related to mysql.
Then, as why the current log files are empty, some log information may be buffered at the time you check the files. To force mysql to write to the files (or the underlying IO libraries) so that the text is visible from outside mysql (ie tail), you can execute (mysql command)
FLUSH LOGS;
There is an interesting article on empty log files.

be sure that variable:general_log=ON,if this variable is "OFF",mysql will not print anything to general_log file.
you can check mysql error log file to look up is there any errors happened

Related

Restore mysql Innodb from filesystem folders

I have a mysql galera server ( innodb) datadir which got crashed with because of network failure . I am trying to restore the db thru the filesystem . tried innodb_force_recovery flag 1 ,
[mysqld]
innodb_force_recovery = 1
Started the database
/etc/init.d/mysql start
Database is up but the the logs shows errors.
2022-03-04 11:07:08 139852880054528 [ERROR] mysqld: Table './mysql/user' is marked as crashed and should be repaired
2022-03-04 11:07:08 139852880054528 [Warning] Checking table: './mysql/user'
2022-03-04 11:07:08 139852880054528 [ERROR] mysql.user: 1 client is using or hasn't closed the table properly
2022-03-04 11:07:08 139852880054528 [ERROR] mysqld: Table './mysql/db' is marked as crashed and should be repaired
2022-03-04 11:07:08 139852880054528 [Warning] Checking table: './mysql/db'
2022-03-04 11:07:08 139852880054528 [ERROR] mysql.db: 1 client is using or hasn't closed the table properly
2022-03-04 11:07:08 139852878686976 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
Repaired the table
bash-4.2$ myisamchk -r --update-state /var/lib/mysql/mysql/user.MYI
- recovering (with sort) MyISAM-table '/var/lib/mysql/mysql/user.MYI'
Data records: 15
- Fixing index 1
bash-4.2$ myisamchk -r --update-state /var/lib/mysql/mysql/db.MYI
- recovering (with sort) MyISAM-table '/var/lib/mysql/mysql/db.MYI'
Data records: 18
- Fixing index 1
- Fixing index 2
Restarted the db server
/etc/init.d/mysql start
The db server is coming up . but showing only information_schema database . no other database is listed not even system db like mysql,performance_schema.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.1.24-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.02 sec)
Checked the datadir and the folders and all looks good . Any change in process or different process to get it working?

Resetting MySQL root password giving error when running init-file

I know there are countless questions and posts about this, but I'm getting an error when trying to start the MySQL Server and I don't know how to solve it.
So to explain I cannot access my database so I tried to reset the password of the root user. I've followed this guide however I've had no luck. First I had issues with permissions on my machine and now I'm getting this error:
1105 Bootstrap file error, return code (0). Nearest query: ''
Technically the MySQL Server is starting, however the init-file is not being run, and so my password is not being reset.
Command I am running is this:
mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 5.7\\my.ini" --init-file=C:\\mysql-init.txt --console
Contents of mysql-init.txt
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
The following is the part of the log where the error is shown:
[Note] Execution of init_file 'C:\\mysql-init.txt' started.
[ERROR] 1105 Bootstrap file error, return code (0). Nearest query: ''
[Note] Execution of init_file 'C:\\mysql-init.txt' ended.
[Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: ready for connections.
MySQL Version: 5.7
OS: Windows 10
Actually you can pass the command:
--init-file=C:\\mysql-init.txt
as a parameter to start the MySQL service from its general tab.
(Source)
Had two errors with MySQL 5.7.24
1.) The script file must be in a separate folder (not mysql installation folder or data directory)
and that folder must get "secure-file-privileges"
2.) The error above was raised for the script did not end with a ';'
Succeeded then with command line statement as
mysqld --datadir=D:\ProgramData\mysql\data --init-file=D:\ProgramData\mysql\reset\reset.sql --secure-file-priv=D:\ProgramData\mysql\reset --console
and SQL-script file 'reset.sql' as
alter user 'root'#'localhost' identified by 'root_pwd';
For me, on Ubuntu, problem was init file was not owned by mysql user.
chown mysql:mysql /tmp/reset_mysql_pswd.sql
sudo mysqld --init-file=/var/lib/mysql/reset_mysql_pswd.sql
# ^C or kill -9 <mysqld pid>
systemctl stop mysql.service
systemctl start mysql.service
Even when the folder containing the init file and the init file itself had permissions 777 (which is a bad idea), I still get:
2020-04-10T23:14:48.030719Z 0 [Note] Execution of init_file '/tmp/reset_mysql_pswd.sql' started.
2020-04-10T23:14:48.030764Z 0 [ERROR] mysqld: File '/tmp/reset_mysql_pswd.sql' not found (Errcode: 13 - Permission denied)
2020-04-10T23:14:48.030772Z 0 [ERROR] Aborting

XAMPP OS X MariaDB datadir changed: mysql does not start

I downloaded XAMPP for OS X 5.6.14 for OS X that includes MariaDB.
Now I want to change the datadir from the database but that does not work. If I start mysql the lights from XAMPP controls are red but the service "mysql" is running...
my.cnf looks like this:
[client]
socket = /Users/tobias/Documents/Webserver/mysql/mysql.sock
[mysqld]
socket = /Users/tobias/Documents/Webserver/mysql/mysql.sock
datadir = /Users/tobias/Documents/Webserver/mysql/
innodb_data_home_dir = /Users/tobias/Documents/Webserver/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /Users/tobias/Documents/Webserver/mysql/
I copied all files from the old directory to the new one and tried to start mysql.
After that, I got this error messages:
2015-12-05 19:50:18 140735225118720 [ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
2015-12-05 19:50:18 140735225118720 [ERROR] Incorrect definition of table mysql.event: expected column 'sql_mode' at position 14 to have type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH'), found type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_A
2015-12-05 19:50:18 140735225118720 [ERROR] Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
Then I run mysql_upgrade and the errors were gone.
I've got no error in log but database does not start... service is running, but lights in Manager are red. phpmyadmin can not connect to db
Does anybody has an tutorial how I can move mysql database directory to a new one?
Permissions of the new folder is set to mysql:mysql
Thanks!

How is MySQL Uptime's value "computed"?

According to MySQL Documentation, the global variable Uptime is defined as "The number of seconds that the server has been up.".
However, can somebody please explain to me how this value is actually computed? What does it use as a reference, System Time?
I am asking this question because I just came across a weird situation : when rebooting a VM with MySQL, ntpd service terminated, and at startup (since was not on chkconfig), the time got shifted +8 hours, as you can see by the following :
15:01:00 hostname shutdown[30383]: shutting down for system reboot
15:01:00 hostname init: Switching to runlevel: 6
...
15:01:06 hostname ntpd[27553]: ntpd exiting on signal 15
15:01:06 hostname syslog-ng[27399]: Termination requested via signal, terminating;
...
23:04:03 hostname kernel: Bootdata ok
The same shift is recorded in the MySQL error logs :
15:01:03 InnoDB: Starting shutdown...
15:01:05 InnoDB: Shutdown completed; log sequence number 2746293826
15:01:06 [Note] /usr/sbin/mysqld: Shutdown complete
15:01:06 mysqld_safe mysqld from pid file /var/lib/mysql/data/hostname.pid ended
23:04:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql/data
After we fixed the time by starting ntpd, it seemed that the Uptime got shifted :
mysql> show global status like 'Uptime';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Uptime | 18005 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show global status like 'Uptime_since_flush_status';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| Uptime_since_flush_status | 18007 |
+---------------------------+-------+
Is this behavior possible, or it probably related to other factors?
Thank you for your patience and understanding.
Should be very simple. The application will create a timestamp from when it starts and compare it to the current time. These times are given from the system time.
So if you modify the system time, it will not adjust the initial timestamp. It will consider the time change as the current time and relay that as its comparison.

Fail to stop mysql (Unable to lock ./ibdata1, error: 11) [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Since two days, I can't connect to mysql with my root account.
I have no problem to log in with the other accounts.
I first thought my server was hacked and that somebody changed the password. I tried to reset it. To do so, I had to use mysqld_safe and therefore to stop mysql, that I failed to do:
> sudo /etc/init.d/mysql stop
Stopping MySQL database server: mysqld failed!
> mysqld stop
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
130107 13:48:34 InnoDB: Unable to open the first data file
[...]
InnoDB: Error in opening ./ibdata1
130107 13:48:34 InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.1/...ror-codes.html
InnoDB: Could not open or create data files.
InnoDB: If you tried to add new data files, and it failed here,
InnoDB: you should now edit innodb_data_file_path in my.cnf back
InnoDB: to what it was, and remove the new ibdata files InnoDB created
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
130107 13:48:34 [ERROR] Plugin 'InnoDB' init function returned error.
130107 13:48:34 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
mysqld: Too many arguments (first extra is 'stop').
MySQL couldn't read ibdata1, so I check its permissions that looks correct:
> ls -l /var/lib/mysql/
-rw-rw---- 1 mysql mysql 18874368 Jan 7 12:39 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Jan 7 13:05 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Jan 7 13:05 ib_logfile1
I tried to move and copy the file like explained here, without any success:
> mv /var/lib/mysql/ibdata1 /var/lib/mysql/ibdata1.bak
> cp -a /var/lib/mysql/ibdata1.bak /var/lib/mysql/ibdata1
Here is a part of my.cnf
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
LANGUAGE = /usr/share/mysql/english
skip-external-locking
The datadir is correct.
As well, here is what happens when I try to get MySQL status:
# sudo /etc/init.d/mysql status
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'debian-sys-maint'#'localhost' (using password: YES)'
I found a solution to this problem on this page, but I have to log in as a root user to do so, that I can't do. I guess the two problems are linked.
Does anyone of you knows how to fix this? I'm blocked in my work because of this.
Thank you a lot for reading this message and maybe to reply to it.
Have a nice day!