Is there a query like
pseudo-code:
SELECT databases FROM mysql.databases WHERE owner = 'myUser'
or any query that'd do the job?
Open the Command Prompt and navigate to the bin folder of your MySQL Server installation directory. Then connect to the server using the mysql -u root -p command. Enter the password and execute the SHOW DATABASES; command we have discussed above.
MySQL COUNT() Function The COUNT() function returns the number of records returned by a select query.
We can see the currently logged user in the database server by using the following query in the MySQL server: mysql> SELECT user, host, db, command FROM information_schema.
SELECT COUNT(*) AS "Number of employees" FROM employees WHERE salary > 75000; In this COUNT function example, we've aliased the COUNT(*) expression as "Number of employees". As a result, "Number of employees" will display as the field name when the result set is returned.
SELECT COUNT(*) FROM information_schema.SCHEMATA;
(run as the user in Question)
SELECT count(*) FROM (
SELECT DISTINCT TABLE_SCHEMA FROM information_schema.SCHEMA_PRIVILEGES WHERE GRANTEE LIKE("'USERNAME'%") GROUP BY TABLE_SCHEMA
) AS baseview;
(Run as root)
Caveat: There is no such thing as an "Owner" for a database in MySQL, the above queries will show information about the databases a user has soem sort of access to.
As far as I can tell, there is no concept in MySQL of "Owner" of database or its objects, as there is in MS Access and MS SQL Server. I surmise this from the lack of "owner" field anywhere in mysql system tables. (http://www.wideman-one.com/gw/tech/mysql/perms/index.htm)
You can count how many databases are associated with a user in the mysql database and the db table. This is the closest I can think of to "ownership" of a database by a user.
SELECT count(DISTINCT Db) FROM db WHERE User = 'someuser';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With