All rows not visible for other users in MySQL - mysql

I have a MySQL instance set up on my machine and other users are connected to the database set up on my machine.
But whenever they do
Select * from table_name;
They are not able to see all the rows present in the table, whereas I am able to see.
All of them are able to see same number of rows.
I have granted them all privileges as well by using the following query.
grant all ON * . * TO 'username'#'hostname';
Any help would be appreciated.
Thanks in advance.

Yes.
Got the answer.
There is an option of toggle number of records limitations in mysql.
After clicking on that option, now they are able to see the number of rows.

Related

Best way to facilitate access to the results of specific queries only

I'm currently in the process of implementing a monitoring system, part of which includes monitoring certain aspects of a MySQL database, such as:
The replication state of the given MySQL instance (sys table)
The number of records in database 1's table x (db1.tableX)
The sum total of a given attribute in another db's table (db2.tableY.column3)
These 3 things can be found using very simple queries:
SELECT viable_candidate FROM sys.gr_member_routing_candidate_status
SELECT COUNT(1) FROM db1.tableX
SELECT SUM(column3) FROM db2.tableY
However, this then requires a user account to be made with at least read access to 3 entire databases / tables.
Is there instead a way to limit access to the results of given queries only? I wondered about making an additional database which is somehow linked to the output of the above 3 queries, and then creating a new user with access only to this database, but I'm not sure what this technology is, or how it would work?
Thanks in advance!
Create a view based on each query and then grant only a select permission to such view.
Example:
CREATE VIEW dbo.view_name AS
SELECT viable_candidate
FROM sys.gr_member_routing_candidate_status
And then
GRANT SELECT ON dbo.view_name TO 'user1'#'localhost'

Can a mysql user be restricted to a max number of rows per select query?

I've found that it's possible to grant user access to only specific tables in a DB. The next part of the puzzle is restricting the scope of select queries.
Should my frontend server ever be compromised by someone able to script, they may attempt to use mysql credentials from the server to dump the database.
If everything is limited to only select, update, and insert queries via mysql privileges, the supposed malicious user could still select * on the tables the mysql user has access to. Perhaps I'm overly paranoid, but I'm wondering if anything can be done to restrict that too.
The assumption here is that if the server is compromised, the mysql user can be used via a script on the server to get a copy of everything in the DB. I'm trying to find the options to protect my (and my users' data).
By design, the frontend application that will use this mysql user will never need to return more than 20 rows (mostly due to hardcoded . I'm therefore happy to restrict the mysql user from ever getting more than 20 rows from a select query.
Can this be done using mysql privileges for that mysql user?
You could create view as select ... limit 20, remove select privilege from the table and grant it only for the view instead.

mysql: specifiy user permissions

is there a way to limit GRANT SELECT user#db with something like a WHERE?
I have variable "PROJECTID" to assess certain records to a particular project.
When user query all clients it should only show the clients from their projects. I do not want to change the interface for every user, so a select where statement will not help here.
Thanks in advance
I fear, there is no such thing.
But you could create database views using a WHERE condition and then give permissions to those views to your users.

SQL Sys.dm_fts_index_keywords_by_document VIEW SELECT Permissions Not Working

I am making use of FULL Text search and I have implemented it by creating a full text catalog and full text index. In order to satisfy the requirement of showing number of occurences of the search keyword I want to access this dynamic management function
dm_fts_index_keywords_by_document (DB_ID('DBNAME'),OBJECT_ID('TABLENAME')) which provides the display term from the file content and its number of occurences.
SELECT *
FROM sys.dm_fts_index_keywords_by_document (DB_ID('DBNAME'),OBJECT_ID('TABLENAME'))
This query statement gets executed without any errors and issues when I ran it by logging in with the login id 'sa' but its failing when i ran it with the user id.
I did try giving SELECT Permissions using
GRANT VIEW SERVER STATE
GRANT VIEW DATABASE STATE
But no luck. Any help would be highly appreciated.
https://technet.microsoft.com/en-us/library/cc280607.aspx states for sys.dm_fts_index_keywords_by_document:
Requires SELECT permission on the columns covered by the full-text index and CREATE FULLTEXT CATALOG permissions.
Assuming the user in question already has SELECT permission you still need to
GRANT CREATE FULLTEXT CATALOG TO userid

List of tables that a user has SELECT privilege for in MySQL

Short version: How can I write an SQL procedure to list which of several tables in a MySQL database a particular user has access to?
Longer version:
I'm writing a multi-user app that accesses a database with data for several branches of a company. The database has a number of lookup tables that any user can access, and a table for each branch that only authorized users can access. My strategy is:
Write a stored procecure that returns a list of the relevant tables for which the user has SELECT privilege.
From the app, call the procedure. If there's only one table returned, use it, otherwise let the user select which branch they want to access (e.g. for managers).
I'm having trouble figuring out how to write such a stored procedure. SHOW GRANTS FOR CURRENT_USER is an obvious possibility, but parsing something like:
GRANT SELECT ON Company.BranchABC TO 'auser'#'%clientdomain.com'
in SQL to figure out what the tables are seems way too messy. Doing a SELECT from the actual tables that hold the permissions also seems problematic, because I'd have to duplicate MySQL's logic for combining the permissions from the various tables (user, db, host, etc.)
Any words of wisdom?
You can see what privileges on which tables a user has:
show grants for 'user'#'host';
For example, to see the privileges of user1 (all machines in the network 10.25), run:
show grants for 'user'#'10.25.%.%';
I have never granted per table permissions to MySQL users before, but to do this, you would check that the TABLE_PRIVILEGES table in the information_schema database.
That should point you in the right direction.
MySQL users list and its privilege can be check with the Query.
select * from mysql.user\G;
http://www.thedevheaven.com/2012/04/retrieve-mysql-users-list-and-its.html