Dropped mysql database and now mysql service won't start - mysql

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

Related

How repair corrupt xampp 'mysql.user' table?

I used Xampp yesterday to create some simple Web-based utility tool.
Today I wanted to continue working on it but xampp control panel gave me some weir errors.
This is the MySQL Error Log:
2019-07-20 23:47:13 0 [Note] InnoDB: Uses event mutexes
2019-07-20 23:47:13 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-07-20 23:47:13 0 [Note] InnoDB: Number of pools: 1
2019-07-20 23:47:13 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-07-20 23:47:13 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2019-07-20 23:47:13 0 [Note] InnoDB: Completed initialization of buffer pool
2019-07-20 23:47:13 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=1819402
2019-07-20 23:47:14 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-07-20 23:47:14 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-07-20 23:47:14 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-07-20 23:47:14 0 [Note] InnoDB: Setting file 'C:\xampp\mysql\data\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-07-20 23:47:14 0 [Note] InnoDB: File 'C:\xampp\mysql\data\ibtmp1' size is now 12 MB.
2019-07-20 23:47:14 0 [Note] InnoDB: Waiting for purge to start
2019-07-20 23:47:14 0 [Note] InnoDB: 10.3.16 started; log sequence number 1819411; transaction id 257
2019-07-20 23:47:14 0 [Note] InnoDB: Loading buffer pool(s) from C:\xampp\mysql\data\ib_buffer_pool
2019-07-20 23:47:14 0 [Note] InnoDB: Buffer pool(s) load completed at 190720 23:47:14
2019-07-20 23:47:14 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-07-20 23:47:14 0 [Note] Server socket created on IP: '127.0.0.1'.
2019-07-20 23:47:14 0 [ERROR] mysqld.exe: Table '.\mysql\user' is marked as crashed and should be repaired
2019-07-20 23:47:14 0 [ERROR] mysqld.exe: Index for table '.\mysql\user' is corrupt; try to repair it
2019-07-20 23:47:14 0 [ERROR] Couldn't repair table: mysql.user
2019-07-20 23:47:14 0 [ERROR] Fatal error: Can't open and lock privilege tables: Index for table 'user' is corrupt; try to repair it
Tried already to repair, but the mySQL Service won't even start, so I'm kinda helpless...
This is almost certainly a known bug in mariaDB (ie mySQL). See ApacheFriends.org for the description. Problem occurs after user password changes - often user root.
General advice seems to be to cut your losses and downgrade your XAMPP to 7.3.5
Otherwise the problem may later recur even after a complete uninstall/re-install of 7.3.7 for example.
What follows is a circumvention / repair for Windows/XAMPP users. It assumes you have a backup - which you probably do. (It appears the installation process provides an initial backup.) Idea is to get you back on air without downgrading long enough for the next release to arrive.
Quickest way out of the swamp is just to go to step 9.
(1) Find 'my.ini' (eg. c:\xampp\mysql\bin\my.ini )
(2) Insert 'skip-grant-tables' in a new line following label '[mysqld]'. Remove this later.
(3) Now mySQL can be started from the XAMPP control panel.
(4) Start phpMyAdmin from browser and select table 'user' from database 'mysql'
(5) Should see: #1034 Index for table 'user' is corrupt; try to repair it.
(6) Select 'mysql' from left panel then check 'user' in right hand panel.
(7) From the 'With selected' dropdown run 'analyze' then 'repair table'.
(8) If 'Repair' fails no choice but to 'DROP TABLE user' ....
(9) Recreate 'user' table from the distribution backup by copying the following 3 files.
C:\xampp\mysql\backup\mysql\user.frm
C:\xampp\mysql\backup\mysql\user.MYD
C:\xampp\mysql\backup\mysql\user.MYI
to
C:\xampp\mysql\data\mysql\
then restarting XAMPP and adding/removing/editing users as you wish.
One last point: There seems to be some sort of association between the 'user' and 'db' tables. You may need to repair the 'db' table as per step (7).
Use bellow command and you will be happy as i am now.
repair table DATABASENAME.TABLENAME use_frm;
I'm sure you know that you should change capitals with your storage preferences and backup before runing this command, don't you? :)
I had problem #1034-Index for table 'db' is Corrupt; try to repair it in phpmyadmin
Step:1
Run these two queries for the damaged table:
REPAIR TABLE mysql.db
REPAIR TABLE mysql.user
Step:2 follow image below:
Check the corrupt tables and then click on the dropdown beside Check all and from the dropdown list select Repair table from the Table Maintenance group.
Just use
REPAIR TABLE mysql.user
For windows:
Go to Xampp folder:
Xampp->mysql->bin
Double click on: mysql_upgrade.exe
after that refresh your browser(phpmyadmin)
The easiest way
Checked that corrupt table and then select/click on Repair table.
try this i hope it will work.
I also encountered this 'bozo' error under XAMPP, version 7.3.16, so I'll be sure NOT to upgrade anytime soon. I use SQLYog to manage my database, so I was able to repair the specific table listed in the error -- mysql.db . I don't know what the command line version of this would be, but here is a screenshot of the options I checked in SQLYog:
Run these two queries:
CHECK TABLE `users`
and
CHECK TABLE `db`
Run the following query for the damaged table
REPAIR TABLE `users`
and/or
REPAIR TABLE `db`
This worked for me, fixed issues with user accounts
repair table mysql.db use_frm
in xampp
localhost/phpmyadmin
here select db as mysql
then run
repair table global_priv;
I had the problem 1034 after changing the password for root user.
I had queried the following in the console at the bottom left of the phpMyAdmin page.
REPAIR TABLE mysql.db
REPAIR TABLE mysql.user
mysql.user is not a table, is a view, thats why cant be repair. Dont worry about it, just fix all the other tables in mysql
Adding the following worked for me.
skip-grant-tables
But after restoring use from the backup folder to data and then removing skip-grant-table again results in MySQL not starting.
I could not get MySQL to run. It kept exiting out. So I wasn't able to run any of the queries others suggested. However, my solution seemed a bit easier for me. I copied the three main db backup files, your root install location may differ, but mine were located at C:\xampp\mysql\backup\mysql.
db.frm
db.MAD
db.MAI
Always backup your files first. Then I copied these files into the data directory overwriting the corrupt files, C:\xampp\mysql\data\mysql.
Once I did this, I was able to start up MySQL perfectly with no errors.
Stop mysql then open my.cnf or my.ini then add
skip-grant-tables
Please copy user table from original (fresh) MySQL:
[path_data]\mysql\user.frm
[path_data]\mysql\user.MYD
[path_data]\mysql\user.MYI
Then running mysql_upgrade
$ mysql_secure_installation
Then follow instruction
This step for me on Laragon (Windows).
select mysql database and run the below command. It worked.
REPAIR TABLE global_priv
I got the same error on Xampp and solved with mysql_upgrade.exe .
Background: I imported a new db in adminer, tried to create a user for that db and got the problem. The db I was trying to import was a dump created with phpmyadmin.
What I did: I executed (from git bash, I'm on Windows 10):
/c/xampp/mysql/bin/mysql_upgrade.exe -u root -p
from the output of this execution I saw several phases with no error but same views of a DB that I imported some time ago, don't have a valid user (I got:
...
Phase 3/7: Fixing views
...
The user specified as a definer ('xxx'#'%') does not exist
...
At the end of this execution I tried to create a user and it worked fine.
Late from the party, but if repair fails, be sure that the user table is an actual table instead of a view. In latter case, you can try to repair with
REPAIR VIEW user;
For windows:
Make sure, your Apache and MySQL keep running.
Go to Xampp folder: Xampp->mysql->bin
Double click on: mysql_upgrade.exe
after that refresh your browser(phpmyadmin)
THIS IS PROVEN AND TESTED
Step 1. In your XAMPP installation directory find the " \phpMyAdmin\libraries\ "
Step 2. In above folder, find this file > " check_user_privileges.inc.php "
Step 3. Open above file in a code editor of your choice and find line number 28
" $checkUserPrivileges->analyseShowGrant(); "
Step 4. Delete Line Number 28 and add below code instead:
$GLOBALS['is_create_db_priv'] = true;
$GLOBALS['is_reload_priv'] = true;
$GLOBALS['db_to_create'] = '';
$GLOBALS['dbs_where_create_table_allowed'] = array('*');
$GLOBALS['dbs_to_test'] = false;
$GLOBALS['db_priv'] = true;
$GLOBALS['col_priv'] = true;
$GLOBALS['table_priv'] = true;
$GLOBALS['proc_priv'] = true;
Step 5. Save file and restart XAMPP.

I am having troubles with Mysql - "about query logging issue"?

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

Mysql doesn´t start after expending data-dir with simlink to another database

I´ve installed mysql and it worked fine.
Now I´d liked to have the data of several databases in my dropbox. So I put symlinks in my mysql data dir.
sudo ln -s /Users/michaelbenker/Dropbox/geschaeft/softwareentwicklung/DB/testdatabase /usr/local/mysql/data/testdatabase
Now when I tried to restart mysql, I get the error
ERROR! MySQL server PID file could not be found!
Starting MySQL
. ERROR! The server quit without updating PID file
(/usr/local/mysql/data/Michaels-iMac-783.local.pid).
In my error file I found this entry
2017-05-26T11:29:12.067923Z 0 [ERROR] InnoDB: Operating system error
number 13 in a file operation.
2017-05-26T11:29:12.067928Z 0 [ERROR] InnoDB: The error means mysqld
does not have the access rights to the directory.
2017-05-26T11:29:12.067934Z 0 [ERROR] InnoDB:
os_file_readdir_next_file() returned -1 in directory ./, crash recovery
may have failed for some .ibd files!
2017-05-26T11:29:12.067963Z 0 [ERROR] InnoDB: Plugin initialization
aborted with error Generic error
2017-05-26T11:29:12.375057Z 0 [ERROR] Plugin 'InnoDB' init function
returned error.
2017-05-26T11:29:12.375090Z 0 [ERROR] Plugin 'InnoDB' registration as a
STORAGE ENGINE failed.
2017-05-26T11:29:12.375097Z 0 [ERROR] Failed to initialize plugins.
2017-05-26T11:29:12.375100Z 0 [ERROR] Aborting
So I tried several things to change the permission to my Dropbox data-dir
I tried to change the owner to mysql (tried also _mysql)
I tried to change the group to mysql (tried also _mysql)
I tried to change the chmod to 777
Nothing helped.
I did the same on my MacBook and here everything worked fine.
Here the actual permissions on the Dropbox Dir
drwxrwxrwx# 5 _mysql _mysql 170 26 Mai 13:02 DB
MySQL will also need to be able to change into the parents of the Dropbox directory, which implies a +x on each one.

The server quit without updating PID file '

I use the command:
/usr/local/Cellar/mysql/5.6.26/support-files/mysql.server start
to start the database and get the error info:
ERROR! The server quit without updating PID file(/usr/local/var/mysql/macbooks-MacBook-Pro.local.pid).
The local.err has the following information:
151103 20:43:37 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2015-11-03 20:43:37 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-03 20:43:37 0 [Note] /usr/local/Cellar/mysql/5.6.26/bin/mysqld (mysqld 5.6.26) starting as process 42772 ...
2015-11-03 20:43:37 42772 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2015-11-03 20:43:37 42772 [Note] Plugin 'FEDERATED' is disabled.
/usr/local/Cellar/mysql/5.6.26/bin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied)
2015-11-03 20:43:37 42772 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
Your MySQL installation appears to be damaged. You have an error but the proposed resolution isn't likely to help:
/usr/local/Cellar/mysql/5.6.26/bin/mysqld: Can't find file: './mysql /plugin.frm'
(errno: 13 - Permission denied)
2015-11-03 20:43:37 42772 [ERROR] Can't open the mysql.plugin table.
Please run mysql_upgrade to create it.
As you see, MySQL cannot open a file, but not because it does not exist; rather because it has no rights to do so (error 13).
From the console, verify the status of the mysql/plugin.frm file in the 'mysql' directory. You'll need to find the MySQL data directory (mysql).
Supposing it's /usr/local/var/mysql/, you would do
ls -la /usr/local/var/mysql/ | more
(SPACE or ENTER to page the output) and see a row containing "plugin.frm".
If there is not, then running the mysql_upgrade command might fix things (but backup the mysql installation and data directory first! Just in case).
If there is, verify it has the same user and group as the other files. Chances are that the other files will be owned by Cellar/users and this, maybe, by root/wheel. As administrator (su), try running
chown Cellar:users ./mysql/plugin.frm
and this should fix the Errno 13, and possibly the PID trouble as well.
Failing everything else, reinstalling MySQL could be a solution. You'll install the same version 5.6.26, then verify the data directory and, if necessary, overwrite it with your backup, having care to preserve the new ownerships and permissions.
This trick isn't guaranteed to work between different MySQL versions and OSes, but on the same machine with the same MySQL version and OS it stands excellent chances.
You can also run a partial restore of only the databases you need (for example you can skip restoring the mysql tablespace where all users and permissions are. You'll lose them, but the data will still be accessible in the other databases).

MySQL won't start in CentOS 5.5 and the "ERROR 2002"

I would like to ask a help for the problem I encountered. My mysql server suddenly stopped after I install php-soap. I don't know why it get stopped actually...
Since it's stopped I tried to start it by typing the line:
# /etc/init.d/mysqld start
After this, I get this message:
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
Starting mysql seems failed. Since I tried it numerous times and got this result a numerous time. I checked the mysqlog and here's what I got.
==== MYSQL LOG ====
120511 21:34:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120511 21:34:43 [ERROR] Error message file '/usr/share/mysql/english/errmsg.sys' had only 481 error messages,
but it should contain at least 641 error messages.
Check that the above file is the right version for this program!
/usr/libexec/mysqld: Unknown error 1146
120511 21:34:43 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120511 21:34:43 InnoDB: Initializing buffer pool, size = 8.0M
120511 21:34:44 InnoDB: Completed initialization of buffer pool
120511 21:34:44 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
120511 21:34:44 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Other infos:
OS: CentOS 5.5 64bit
Mysql Version: Sorry I couldn't get the version of mysql installed on my server due this error I am getting:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Can somebody help me to resolve this problem?
Thank you in advanced.
looks like your installation of mysql is not corrupt with /usr/share/mysql/english/errmsg.sys having been modified to contain less than the number of entries needed.
i would get the installation/src files for mysql for your centos box again. Untar it and locate the file errmsg.sys from sql/share/english, copy it to /usr/share/mysql/english/errmsg.sys and restart your mysqld. Another option is just to reinstall mysql from centos repo, after backing up your dbs to make sure they don't get blown away and to have a copy/backup of it.
I would also find out what made the changes to the errmsg.sys file.