Used chown for /var/lib/mysql to change owner from root, now getting Error 1049 (42000) in mysql
The normal ownership of everything in /var/lib/mysql
is mysql:mysql
. So you should be able to fix it with:
sudo chown -R mysql:mysql /var/lib/mysql
Wei
Updated on April 25, 2020Comments
-
Wei about 4 years
With Ubuntu, I previously created a mysql database using the following code in the terminal:
$ my sql -u root -p
Then within mysql:
CREATE DATABASE securities_master;
I was trying to use file explorer to view the contents related to this database. But because I did not have permissions to open the folder /var/lib/mysql I wanted to change the permissions on this folder. I did some searching on stackoverflow, and without fully understanding what I was doing, I used something like the following (my username being wei):
sudo chown -R root:wei /var/lib/mysql
OR (unfortunately I had since closed terminal window so not sure exactly what I typed)
sudo chown -R wei:wei /var/lib/mysql
OR
sudo chown -R wei /var/lib/mysql
This allowed me to view inside the directory and see my files, so I thought I was making progress. However, once I had done this I realized that when I tried to USE the database in mysql:
USE securities_database;
I was getting an error message like:
ERROR 1049 (42000): Unknown database 'securities_master'
I believe this is related to my use of chown earlier. Upon looking into this with further stackoverflow searches, I'm now under the impression I shouldn't be willy nilly taking away root ownership of some files from root as "bad things can happen". I've tried to restore root ownership with:
sudo chown -R root /var/lib/mysql
AND/OR:
sudo chown -R root:root /var/lib/mysql
But unfortunately I seem to still get the same error message.
I apologize if my question seems so basic, or such a rookie error, total newbie to Ubuntu, Linux and mysql here. Thanks.
-
Wei about 7 yearsThat 3 line comment solved my problem in 10 seconds after I had spent 4 hours trying to solve it myself prior to that. I wish I could upvote (but have reputation less than 15), and if you lived closer to me I would buy you a beer. Thanks again.
-
Barmar about 7 yearsYou can accept the answer, it's better than upvoting.
-
Barmar over 4 yearsI don't know Windows system administration.
-
Barmar over 4 yearsHow did you accidentally change the ownership in the first place? You should be able to change it back with the same command.
-
Pervaiz Iqbal over 4 yearsi didnt - basically mysql server is attacked with ransom i am following this article to recvover db bobcares.com/blog/mysql-tablespace-is-missing-for-table stuck on step 4
-
Barmar over 4 yearsYou could try searching for this information in the MySQL Windows Installation documentation I looked at a few pages and didn't see anything about ownership.