Used chown for /var/lib/mysql to change owner from root, now getting Error 1049 (42000) in mysql

老子叫甜甜 提交于 2020-05-13 03:38:08

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/43593736/used-chown-for-var-lib-mysql-to-change-owner-from-root-now-getting-error-1049

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!