Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Error: #1142 - SELECT command denied to user

I'm having troubles with a certain query on one of my servers. On all other places I've tested it it works completely fine but on the server i want to use it it isn't working.

It's about the following SQL:

SELECT facturen.id            AS fid,         projecten.id           AS pid,         titel,         facturen.totaal_bedrag AS totaal,         betaald,         datum  FROM   facturen,         projecten  WHERE  facturen.project_id = projecten.id         AND projecten.eigenaar = '1'  ORDER  BY datum DESC  

This is the error code I get from it:

SELECT command denied to user 'marco'@'localhost' for table 'projecten'

The tables: facturen:

CREATE TABLE IF NOT EXISTS `facturen` (   `id` int(11) NOT NULL auto_increment,   `project_id` int(11) NOT NULL,   `datum` int(11) NOT NULL,   `lever_datum` int(11) NOT NULL,   `totaal_bedrag` decimal(9,2) NOT NULL,   `btw` decimal(9,2) NOT NULL,   `bedrijf` varchar(40) NOT NULL,   `contactpersoon` varchar(60) NOT NULL,   `adres` varchar(60) NOT NULL,   `postcode` varchar(7) NOT NULL,   `plaats` varchar(30) NOT NULL,   `betaald` int(11) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=201200006 ; 

projecten:

CREATE TABLE IF NOT EXISTS `projecten` (   `id` int(11) NOT NULL auto_increment,   `titel` varchar(80) NOT NULL,   `eigenaar` int(11) NOT NULL,   `creatie_datum` int(11) NOT NULL,   `eind_datum` int(11) NOT NULL,   `totaal_bedrag` decimal(9,2) NOT NULL,   `btw` decimal(9,2) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=201200004 ; 

The strange part is that every other query on both the 'projecten' table and the 'facturen' table works completely fine, also this query works fine on two other servers of mine.

like image 523
Seph Avatar asked Jun 08 '12 21:06

Seph


People also ask

What is the MySQL error?

Network conditions should be checked if this is a frequent error. If an error message like “Lost connection to MySQL server” appears while querying the database, it is certain that the error has occurred because of network connection issues.

How can I see MySQL errors?

The SHOW COUNT(*) ERRORS statement displays the number of errors. You can also retrieve this number from the error_count variable: SHOW COUNT(*) ERRORS; SELECT @@error_count; SHOW ERRORS and error_count apply only to errors, not warnings or notes.

Why MySQL is not working?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.


2 Answers

I faced the same situation but its funny that reason for the error was due to the use of the incorrect database or schema name.

Its true that multiple issues can lead to error you have mentioned.

like image 112
Vaibs Avatar answered Oct 05 '22 23:10

Vaibs


You need to grant SELECT permissions to the MySQL user who is connecting to MySQL

same question as here Error: select command denied to user '<userid>'@'<ip-address>' for table '<table-name>'

see answers of the link ;)

like image 28
khaled_webdev Avatar answered Oct 06 '22 00:10

khaled_webdev