8

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
  • 428
  • 1
  • 5
  • 13
  • `SHOW databases;` lists your created database? – Dez Apr 24 '17 at 16:51
  • Came up with an error as I had the incorrect ownership, but once I fixed it as per @Barmar 's suggestion, it did indeed show the database, thanks. – Wei Apr 24 '17 at 17:04

1 Answers1

27

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
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    That 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. – Wei Apr 24 '17 at 17:00
  • I don't know Windows system administration. – Barmar Sep 13 '19 at 10:48
  • How did you accidentally change the ownership in the first place? You should be able to change it back with the same command. – Barmar Sep 13 '19 at 10:49
  • i didnt - basically mysql server is attacked with ransom i am following this article to recvover db https://bobcares.com/blog/mysql-tablespace-is-missing-for-table/ stuck on step 4 – Pervaiz Iqbal Sep 13 '19 at 12:42
  • You could try searching for this information in the [MySQL Windows Installation documentation](https://dev.mysql.com/doc/refman/8.0/en/windows-installation.html) I looked at a few pages and didn't see anything about ownership. – Barmar Sep 13 '19 at 12:50