Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Show the current privileges of a MySQL user

Answer:

To show the current privileges of a MySQL user, you can use the SHOW GRANTS statement

E.g.

mysql> SHOW GRANTS;

+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*****************************************' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+

Show the current user in MySQL

Answer:

Like in the shell, we can execute the command whoami to find out the current user name, we can use the function CURRENT_USER();

E.g.

mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

Select a document in MongoDB

Answer:

To select (find) a document in MongoDB, you can use the following syntax in the mongodb Interactive shell.

use my_db
db.users.find({name:"peter"})

You need to switch to the current database (e.g. my_db) and then execute your select statement.

Explain query execution plan in MongoDB

Answer:

Like MySQL, you can get a better understanding of the performance of your MongoDB's query, you can use the $explain feature.

E.g.

db.collection.find(query).explain();

Disable MySQL server from listening for TCP/IP connections

Answer:

If you only connect to the MySQL server from localhost and you might want to disable TCP/IP networking feature so the server is more secure.

To do so, edit the MySQL configurations, e.g. /etc/my.cnf

..
skip-networking
..

Don't forget to restart MySQL to take effect.

# /sbin/service mysqld restart