I have written a PHP script to be executed by CRON on a daily basis to clean files and remove old database entries..
The script has no problems being run, so I know its not a CRON issue.
The problem is that I get the following error:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'username'#'localhost' for table 'users' in /cron_removeOld.php on line 35
I am using the same DB credentials for the backend admin users, so I know they have SELECT privileges. I'm wondering if it has something to do with the script being run outside of the webserver?
Any help would be greatly appreciated!
Cron:
20 0 * * * php -q /home/user/public_html/tssol/contract/admin/cron_removeOld.php
PHP (Line 35):
$stmt = $dbh->prepare("SELECT idusers, contract FROM users WHERE contractExpireDate <= NOW()");
The db creds are in an include file that is shared with other pages so I know thats not an issue..will post if you think it will help
MySQL permission has nothing to do with PHP executed by CLI or whatever.
Check if your mysql user has the SELECT provileges for users table
Related
As mentioned by others (Ref 1,
Ref 2 and Ref 3) the current phpMyAdmin version (4.8.2) + MySQL 8.0.11 + PHP 7.2.8 doesn't work as expected.
The error happens when you try to open phpMyAdmin, where it shows an error message:
#2054 - The server requested authentication method unknown to the client
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
As stated in MySQL migration manual here, and described as the solution in Ref 2, you can correct this by executing the following mysql query inside docker:
ALTER USER root IDENTIFIED WITH mysql_native_password BY 'ROOTPASSWORD';
(In order to run this, I use docker exec -it CONTAINERID bash and execute mysql command)
And it works. The main problem is that I need to fire this query as soon as the container starts (the current method is manual and far from scalable). I assume it's possible in different ways:
By executing a PHP script that runs the query after everything has been setup (IMO this is unsafe )
By running the above command in a bash after everything has been setup
The first one is unsafe IMO as the mysql user must have high privileges, although there will be only the root user when this script runs. I haven't tested it yet.
The seconde one is the best IMO, but I can't figure it out how to implement using Dockerfile, as everything I type there runs BEFORE mysql and phpMyAdmin are installed. How could I achieve that?
My current Dockerfile can be seen here and the docker-compose.yml can be seen here.
As a simple solution, you can build your custom mysql image and run the command there. Then mysql will start with this modification already in place.
I am working on a project using the Laravel 4.2 framework. I want to execute the command php artisan migrate but when I run this command it shows an error:
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1142 CREATE command denied to user 'abc'#'10.1.1.27' for table 'migrations'
I think I have placed the project files and the database on different servers, so that's why am I getting this error.
Database server: 10.1.1.56
Project server: 10.1.1.27 (localhost)
This error indicates that the remote MySQL database isn't configured to allow certain operations executed by the user abc from the IP address 10.1.1.27. In many cases, MySQL users are set up to allow access from the the same host as the database server, but we need to explicitly GRANT access for clients connecting to the database from a remote host.
We can use the following commands to grant the user abc access from remote hosts. We must run these commands as a user that has the ability to grant privileges to other users (such as the database's root user):
GRANT ALL PRIVILEGES ON database.* TO 'abc'#'%';
FLUSH PRIVILEGES;
Replace database with the name of the application's database configured in .env or config/database.php. The wildcard '%' in 'username'#'%' indicates that we want to give permissions to that user from any IP address. If we don't want to allow the user access from any IP address, we can limit access to specific IP addresses by replacing the wildcard with the address to allow (10.1.1.27 in this case).
Depending on the needs of the project, we may not need to give a user all privileges to a database. See the documentation for a list of available privileges that we can assign.
1142 CREATE command denied to user 'abc'#'10.1.1.27' for table 'migrations'
The above command simply means that the user don't have CREATE permission on the connected database. So first of all you have to grant the privileges to that user on the database and after that run the migration.
Explanation: When you run migrate, a table is created on with the name migration in the database that maintains the status of migration ion it, and you don'r have the CREATE permission that's why it is showing error.
I am creating an API REST aplication with Symfony3, and I have this problem. When I execute the methods in localhost it works fine, but I have uploaded the project to a server administered with Plesk, and when I try to execute the methods with postman, it shows this:
An exception occurred while executing 'SELECT t0.random_id AS ...'
with params [\"a\", \"a\"]:\n\nSQLSTATE[42000]: Syntax error or access
violation: 1142 SELECT command denied to user 'app'#'localhost' for
table 'table_name'
It seems to be a permissions problem, but if I try to access to the database with MysQL Workbech, with the same credentials, I can do it and execute querys without problems. And in the Plesk panel, the user has all the permissions and privileges.
I have also tried changing "localhost" for the host address in the parameters file of Symfony.
Looks like app user doesn't have permissions to execute SELECT query.
Run following MySQL query to fix it:
GRANT SELECT on database_name.* to 'app'#'localhost' identified by 'your-pass';
FLUSH PRIVILEGES;
I am running into a permission error when trying to load data from a flat file database dump into a new table. I know that the schema of the file and my table is the same and I tried tweaking the permissions. What else should I try?
mysql> load data infile 'myfile.txt' into table mytable fields terminated by ',' enclosed by '"';
ERROR 1045 (28000): Access denied for user 'user'#'%'
grant all on mytable.* to 'user'#'%
Here's a thread on the MySQL forums that discusses exactly this.
Here's the answer, posted by Ken Tassell
Problem resolved using the command below:
grant file on *.* to kentest#localhost identified by 'kentest1';
You might have MySQL privileges on the destination table, but you also need the FILE privilege to execute LOAD DATA, and of course the MySQL Server process needs operating-system privileges to the data file too.
I am using xampp om windows 7. I logged in as the root user with the password i have set up. I created a new database(I am using xampp for the first time). and I am not getting any option for creating any tables in it.
It shows the following error:
Error
SQL query: DocumentationEdit
SELECT `tables`
FROM `phpmyadmin`.`pma_recent`
WHERE `username` = 'root'
MySQL said: Documentation
#1142 - SELECT command denied to user ''#'localhost' for table 'pma_recent'
How do I get rid of this?
I get this line also, somewhere at the bottom of the page along with the error message:
The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated.
http://dev.mysql.com/doc/refman/5.1/en/grant.html
GRANT SELECT ON db.table TO 'user'#'localhost';
GRANT ALL ON db1.* TO 'jeffrey'#'localhost'; ------------ i think this is much better.