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?
Related
I tried to upload a new version of an image file to my wiki and got this error:
Error 1034: Index for table 'oldimage' is corrupt; try to repair it (localhost)
I am running Mediawiki 1.35.6 on an Ubuntu Mate 22.04 LTS linux box (my private wiki). PHP 8.1.2, and Apache/2.4.52.
I don't know how to do this repair the error suggests.
UPDATE: I can sudo mysqlcheck -c mywiki oldimage and got the following result:
rwp#wiki:/var/lib/mysql/mywiki$ sudo mysqlcheck -c mywiki oldimage
mywiki.oldimage
Warning : InnoDB: Index 'oi_actor_timestamp' contains 15 entries, should be 12.
Warning : InnoDB: Index 'oi_name_timestamp' contains 15 entries, should be 12.
Warning : InnoDB: Index 'oi_name_archive_name' contains 15 entries, should be 1 2.
Warning : InnoDB: Index 'oi_sha1' contains 15 entries, should be 12.
error : Corrupt
I don't know what command to issue to repair oldimage.
UPDATE 2: I did the following from CLI.
sudo mysql
show databases;
use mywiki;
repair table mywiki.oldimage use_frm;
And result is:
MariaDB [mywiki]> repair table mywiki.oldimage use_frm;
+-------------------+--------+----------+---------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-------------------+--------+----------+---------------------------------------------------------+
| mywiki.oldimage | repair | note | The storage engine for the table doesn't support repair |
+-------------------+--------+----------+---------------------------------------------------------+
Ok, here is the solution I fumbled around onto (thanks to #erik258).
First, I stopped the web server that uses the database.
sudo service apache2 stop
Then,
sudo mysql
show databases;
use mywiki;
repair table mywiki.oldimage use_frm;
The repair did not work because the table, being InnoDB, did not support a repair. So, I altered the table to MyISAM as per here first. Did the repair, and then converted it back to InnoDB.
sudo mysql
show databases;
use mywiki;
alter table mywiki.oldimage engine=MyISAM;
repair table mywiki.oldimage use_frm;
It reported table repaired. Then I changed it back to InnoDB and all working fine now.
alter table mywiki.oldimage ENGINE=InnoDB;
quit;
Then restarted the web server that uses this database.
sudo service apache2 stop
By mistake I dropped mysql database which contains configuration for mysql service itself and now the service won't start. Here is the log at startup :
100 200
2018-10-17T06:31:21.364556Z 0 [Warning] InnoDB: New log files created, LSN=2939944
wampmysqld64: Table 'mysql.plugin' doesn't exist
2018-10-17T06:31:21.748646Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2018-10-17T06:31:21.749764Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-10-17T06:31:21.754394Z 0 [Warning] Failed to open optimizer cost constant tables
2018-10-17T06:31:21.803432Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2018-10-17T06:31:21.804295Z 0 [ERROR] Aborting
Is there a way to restore it to the original without reinstalling everything (it was bundled in wamp server so I would have to reinstall everything).
To restore fresh mysql system after accidental removal of a system database you have to :
Rename or delete the data folder in mysql install folder otherwise the next step will yield an error.
Run one of these commands from windows console :
C:> bin\mysqld.exe --initialize
C:> bin\mysqld.exe --initialize-insecure
i want to save the queries of my mysql to a .out/.log/.txt file on my desktop. I am using a Mac machine. i saw my friend use "tee" linux command in mysql to log the queries like
tee ~/Desktop/mylog.txt
above command worked on his laptop running windows but shows an error-
( Can't create/write to file '~/Desktop/mylog.txt' (Errcode: 2 - No such file or directory)
Error logging to file '~/Desktop/mylog.txt')
on my laptop. Once i tried with no file on my desktop to let it create one, then i pre-created one. but in both cases it was not working.
then i also tried this one below:-
mysqld --log=~/Desktop/myquery.log
this also doest work and gives an error:
mysqld: Can't change dir to '/usr/local/mysql-5.7.18-macos10.12-x86_64/data/' (Errcode: 13 - Permission denied)
2017-09-05T08:35:50.566311Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-05T08:35:50.567503Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2017-09-05T08:35:50.567630Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 25981 ...
2017-09-05T08:35:50.602972Z 0 [Warning] Can't create test file /usr/local/mysql-5.7.18-macos10.12-x86_64/data/Lohitakshs-MacBook-Air.lower-test
2017-09-05T08:35:50.603050Z 0 [Warning] Can't create test file /usr/local/mysql-5.7.18-macos10.12-x86_64/data/Lohitakshs-MacBook-Air.lower-test
2017-09-05T08:35:50.603305Z 0 [ERROR] failed to set datadir to /usr/local/mysql-5.7.18-macos10.12-x86_64/data/
2017-09-05T08:35:50.603328Z 0 [ERROR] Aborting
2017-09-05T08:35:50.606324Z 0 [Note] Binlog end
2017-09-05T08:35:50.608285Z 0 [Note] mysqld: Shutdown complete
Then i also tried by going SUDO , but that also gave the same error.
Now my problem is that i have too many queries on my screen right now, which i cannot afford to loose, so i need a solution which can solve the issue on my running server.
Thanks a lot
The mysql program doesn't understand the ~ shorthand for your home directory.
If you're in your home directory when you run the mysql command, you can simply type
mysql> tee Desktop/mylog.txt
If not, you'll need to type the full path.
mysql> tee /Users/yourusername/Desktop/mylog.txt
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.
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