MySQL can show tables but cannot access data (errno: 13 - Permission denied) - mysql

I am fixing a server that uses Bitnami to run a WordPress site. I did not set up the server – it ran out of memory and crashed.
I was able to restart MySQL through the bitnami ctlscript, and I am able to access the MySQL CLI, but I cannot execute any queries that return data INSIDE the tables.
The following commands all work, and generate the expected output:
show databases;
use database 'x';
show tables;
As soon as I try to view table data (SELECT * FROM ...), this error shows up:
2019-01-15T18:25:19.507808Z 233 [ERROR] /opt/bitnami/mysql/bin/mysqld.bin: Can't find file: './bitnami_wordpress/wp_options.frm' (errno: 13 - Permission denied)
What I've tried:
Database file permissions. All data (specifically the
wp_tablename.frm files) is chowned by mysql:mysql
I confirmed this by changing permissions to my server user, restarting and trying to access mysql again, but the commands above, which already worked, broke, so I changed it back.
Reboots of all sorts. Bitnami, server, etc.
Selinux. I am 95% sure it is not running on this server (all commands
that check its status / install info return 'use apt-get to
install this package) or something like that.
Please help! This site is in production!

Related

MYSQL no longer starting on Mac with MAMP

Up until today MYSQL was working OK for months with 2 MAMP Drupal localhost builds.
But now MYSQL no longer loads.
When opening MAMP the Apache Server starts,
whereas the MYSQL Server does not start.
This means the "Open WebStart page" option is greyed over and the Drupal path that would normally load the site just displays an error.
Using Terminal, if I run:
which mysql
the response is:
/Applications/MAMP/Library/bin/mysql
But if I try to login into MYSQL via Terminal:
mysql -u (myuser) -p
I am prompted for the password, but after entering correct password I receive:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/Applications/MAMP/tmp/mysql/mysql.sock' (2)
I checked that path, and there is no mysql.sock file there. In that directory there is just one file titled .dummy that has no content in it.
Some forums relating to the same error suggest I check and stop any other running MYSQL instances, but I don't appear to have any.
For example I ran:
ps -ef | grep mysql
And I just receive this:
501 11212 10699 0 12:31pm ttys000 0:00.00 grep mysql
I don't entirely understand that response, but it looks like there is nothing running that I can 'kill'.
Also, if I try things like:
sudo service mysql start
I am prompted for my Mac user password, which I enter, but I am then given the error:
sudo: service: command not found
Any help here would be greatly appreciated.
EDIT: I ran:
mysqld
And received a lot of information! Too long to paste here,
but some things I noticed were:
2019-02-14T03:01:33.211495Z 0 [Note] --secure-file-priv is set to NULL.
Operations related to importing and exporting data are disabled
I don't know how to address the above, but it sounds like it's not helping the situation?
Further on from there, the first 'warning' from the list was:
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
I followed that advice and ran:
mysql_upgrade
and received this error:
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
Any ideas as to how to fix that?
Some other errors I noticed are:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
[ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
[ERROR] Aborting
followed by a lot of lines of "shutting down plugin...(various)..." that ended in:
mysqld: Shutdown complete
Again, I am completely lost here?
After hours of trying out suggestions from various forum threads, such as:
Creating my.cnf files; or
Adjusting the MAMP php.ini file with extra code, or
Reinstalling MAMP again,or
Dumping the "ib_logfile.." files from the MAMP/db/mysql57 directory,
The only thing that finally resolved this for me was:
I suddenly remembered I copied all my working files to a backup.
so I checked the backup directories for MAMP/db/mysql57 and noticed there was a lot of content in there that for some reason was now missing from my live version,
so I deleted everything in the current MAMP/db/mysql57 directory and pasted all the backup items in.
Suddenly MAMP's MYSQL server lights up, the Startup page auto loads into my browser and I can run drush commands in my CLI and load the Drupal CMS again.
Happy Days!

connecting MySQL database to copied and pasted data directory

I copied a database directory from the datadir (/var/lib/mysql/) of a MySQL instance running on a server to my local machine. Is it possible to put this database directory into my local MySQL datadir and access that database?
What I have done so far is copy the database directory like above, I log in to the MySQL and can see the database, I switch to it and can list all the tables. But when ever I try to query a table I get something like:
select * from users limit 1;
ERROR 1146 (42S02): Table 'users' doesn't exist
Also from mysqldump:
mysqldump: Got error: 1146: Table 'very_first_table' doesn't exist when using LOCK TABLES
Is it possible to do what I am trying to do here?
So I got it to work, bare in mind that my end goal was to get a database dump from the database. The mysql folder was extracted from a older virtual machine snapshot which could not be run at the moment, so I couldn't just log in to it and do a normal dump. Here is what I did:
1) I installed mysql on a fresh vm on my local machine
2) I shut down mysql with service mysql stop
3) I removed the existing /var/lib/mysql folder from the fresh install
4) I replaced it with the /var/lib/mysql folder that was removed from the old snapshot
5) I ran chown -R mysql:mysql /var/lib/mysql
6) I restarted mysql with service mysql start
7) Then I checked if I could log in and query the tables, I could!
So I was able to run the dump after that.

Error use mysql-slow.log permission

I've a Galera Cluster Installation with three nodes. As requirement my MariaDB installation must be in different path that default, and user cannot be mysql. So I've moved all mysql data path and I've created a new user and group to manage the mysql service.
MariaDB service is working fine, but I've noticed that a mysql-slow.log has been created with permissions to mysql:root for a third program installation that monitor queries. Opening mysql.err I've found the following error:
[ERROR] Could not use mysql-slow.log for logging (error 13).Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
So I've made chown myuser:mygroup mysql-slow.log and restart the service, but there still having same permissions. Then I've set in my.cnf the slow_query_log=1, in order to try that the myuser create the file at start, but the wrong permission still there also after remove the files and restart.
All the files, in my mariadb data path, are not managed by mysql:mysql user, in my installation are managed by myuser:mygroup so when the mysql-slow.log is created the permissions mysql:root are assigned so I have not permission to write there with myuser:mygroup and if I assign them manually there is not effect because are override with mysql:root after mysql restart.
Somebody knows if there are any way to set by default the user and group owners of the mysql-slow.log file when created?
Thanks.
Regards,
Sergio
Fix the permissions:
chmod 666 mysql-slow.log
See what your script is doing; perhaps it needs fixing, too.

mysqldump: Got error: 1: "Can't create/write to file '*.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'

Linux. No SELinux (disabled).
I try to run this command as my linuxuser (member of group mysql):
mysqldump --user=root --tab "/some/folder" dbname
Getting this error:
mysqldump: Got error: 1: "Can't create/write to file 'sometable.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'
If I look in the folder, there is a sometable.sql file, but no txt file.
As I understand, the sql file is created from the user's name who run the command (linuxuser in my case), but the txt file gets generated by mysql server (mysql user in this case). Note that mysql user is also a member of mysql group.
What could be the problem? Tried everything :)
If you trying to execute a mysqldump in a client diferent that the server
can be a problem
I tried with mysqldump Ver 10.14 Distrib 5.5.56-MariaDB, for Linux (x86_64), and works only with the /tmp/ dir.
Perhaps, help info say that will not work
-T, --tab=name Create tab-separated textfile for each table to given path. (Create .sql and .txt files.) NOTE: This only works if mysqldump is run on the same machine as the mysqld server.
The solution was to change "some/folder" to an external location. Looks like there were permission problems because originally the folder mentioned was under Perforce root and probably it had read-only permissions.
I then changed the new folder permissions to:
mylinuxuser:mysql
making sure that both the user with which the process was started, as well as mysql server have permissions to write there. This is because the sql file is written from user's name and txt file is written from mysql server's name.
I also added my user to the mysql group.
This was something I just found and wanted to pass along for the folks searching for the same answer.
This has been occurring on systems running systemd. In the /lib/systemd/system/mariadb.service file is the setting, 'PrivateTmp=true'. This is a security measure to prevent the data from being seen by folks who shouldn't be seeing it.
If you run:
SELECT * TO OUTFILE '/var/tmp/tablename.txt' FROM TABLENAME;
It will create the file but it creates it in a systemd protected directory.
/var/tmp/systemd-private-[hash]-mariadb-[hash]/tmp/tablename.txt
You can either save the data from here which is perfectly acceptable or stop mariadb, create the directory /etc/systemd/system/mariadb.service.d and in that directory create the file 'mariadb.conf' (as an example; any file should do) with the following:
[Service]
PrivateTmp=false
Run systemctl daemon-reload to reload the configuration and restart mariadb.
You should be able to create backups now.
What has worked for me (in Windows), trying to export a file using:
SELECT * INTO OUTFILE 'C:/documents/dumps' from file
MySQL Service properties --> Log on: take note account defined.
Directory C:\documents\dumps --> properties --> Security: account defined above needs read/write privileges

Starting Mysql in OSX 10 (no brew, no daemon, just a simple start)

I don't want to install MySQL on my computer, I don't want to change configuration of my OS, I want just start the mysql process writing the db on a local folder given from parameters.
I downloaded the mysql bundle from the mysql web site, and tried to start it using the mysqld command inside the bin folder in this way:
./bin/mysqld -b /Users/me/tools/mysql-5.6.28-osx10.10-x86_64 -h ~/Projects/my-project/db
But I have this error when it executes:
2016-01-25 11:13:24 33251 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
Everyone can read and write in the db folder, what can be the problem?
Solved.
I found this page in the mysql doc http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html.
To create and start a new db is needed to execute mysql_install_db (before Mysql v5.7.6) using the appropriate datadir and basedir.
In MySQL 5.6 the script is located under the scripts folder, not in the bin folder as is wrote in the docs.