see details of a database in terminal ubuntu - mysql

I want to see database details such as users that access this database or collation type in mysql, ssh terminal commands.
please help me.
thank you..

You can run mysql console client with --execute parameter for this purpose:
$ mysql -h {hostname} -u {user} -p{password} -e "SHOW PROCESSLIST"
This will produce output similar to the next one:
+----+---------+-----------------+---------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+---------+-----------------+---------+---------+------+-------+------------------+
| 1 | root | {hostname}:3786 | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
+----+---------+-----------------+---------+---------+------+-------+------------------+

Related

How to import data from .sql file in mysql?

I have a 2.6GB file which I need to import and I used the command
sudo mysql -u root -p <dbname> > ~/<filename>.sql
I created a database from phpmyadmin and ran the above command.
It has been running for 30 minutes and when I run SHOW PROCESSLIST; on a separate window I get this
mysql> SHOW PROCESSLIST;
+-----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+------+---------+------+-------+------------------+
| 149 | root | localhost | test | Sleep | 1716 | | NULL |
| 155 | root | localhost | NULL | Query | 0 | init | SHOW PROCESSLIST |
+-----+------+-----------+------+---------+------+-------+------------------+
2 rows in set (0.00 sec)
What is happening and why is it gone to sleep? How do I solve this?
It turns out that mysql server in preferences keeps shutting down whenever I start it. How do I solve this?

MaxScale blocks direct connect to database

I have a 2 nodes mariadb cluster with one maxscale load balancer.
maxscale blocks connection if i want to connect directly to a database: so for example:
mysql -h 35.300.208.100 -u finn -p works and if i then do a USE test i can do everything with the database "test". so the rights are correct.
but if a do a mysql -h 35.300.208.100 -u finn -p test i get the error:
ERROR 1045 (28000): Access denied for user 'finn'#'188.68.43.150' (using password: YES) to database 'test'
So if i do the same on the nodes with localhost, everything works fine.
This is my maxscale.cnf
Most of the time you will receive ERROR 1045 (28000): Access denied when the grants on the database do not contain matching grants for both the client IP and the MaxScale IP.
The usual way of solving this is to:
Execute SHOW GRANTS on the database from the client server
Execute SHOW GRANTS on the database from the MaxScale server
Compare the output of the two queries and make sure they are identical
This is usually enough to spot any problems with grants in the database.
Another way to resolve these sorts of errors is to execute the query that MaxScale uses to load the database users. The exact SQL for these queries can be found on the MaxScale wiki on GitHub. For MaxScale 2.1 and newer, this would be:
SELECT u.user, u.host, d.db, u.select_priv, u.password
FROM mysql.user AS u LEFT JOIN mysql.db AS d
ON (u.user = d.user AND u.host = d.host)
UNION
SELECT u.user, u.host, t.db, u.select_priv, u.password
FROM mysql.user AS u LEFT JOIN mysql.tables_priv AS t
ON (u.user = t.user AND u.host = t.host);
This should return a result set containing the authentication data that MaxScale uses. Here's an example of what the query can return:
+---------------+-----------+------+-------------+-------------------------------------------+
| user | host | db | select_priv | password |
+---------------+-----------+------+-------------+-------------------------------------------+
| root | localhost | NULL | Y | |
| maxuser | 127.0.0.1 | NULL | Y | *5EDBD32E469DAE0CE10E6999C3899DEFCB9F12E0 |
| root | % | NULL | Y | |
| maxuser | % | NULL | Y | *5EDBD32E469DAE0CE10E6999C3899DEFCB9F12E0 |
| skysql | 127.0.0.1 | NULL | Y | *85058F5DEAD82AE3507664C2C11BDA7B1827B80D |
| skysql | % | NULL | Y | *85058F5DEAD82AE3507664C2C11BDA7B1827B80D |
| test | % | NULL | Y | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 |
| stackoverflow | % | test | N | *5635C63172887A7D7C0828876228A5E4DC523969 |
| stackoverflow | % | NULL | N | *5635C63172887A7D7C0828876228A5E4DC523969 |
+---------------+-----------+------+-------------+-------------------------------------------+
The select_priv tells whether the user is allowed to connect with any default database. If it is set to N, then the value in the db column is the only database that the client is allowed to use. As we can see from the example result, the 'stackoverflow'#'%' user is either allowed to connect without a default database or with the test default database.

Killing sleeping processes in Mysql?

Can anyone tell me how can I kill all the sleeping processes?
I searched for it and I found that we can do it by command
mk-kill --match-command Sleep --kill --victims all --interval 10
I connected the DB server(Linux) but I find the message that command not found.
I tried to connect via MYSQL administrator and it doesn't say that command not found but also doesn't executes the query , just says you have an SQl error
login to Mysql as admin:
mysql -uroot -ppassword;
And than run command:
mysql> show processlist;
You will get something like below :
+----+-------------+--------------------+----------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+--------------------+----------+---------+------+-------+------------------+
| 49 | application | 192.168.44.1:51718 | XXXXXXXX | Sleep | 183 | | NULL ||
| 55 | application | 192.168.44.1:51769 | XXXXXXXX | Sleep | 148 | | NULL |
| 56 | application | 192.168.44.1:51770 | XXXXXXXX | Sleep | 148 | | NULL |
| 57 | application | 192.168.44.1:51771 | XXXXXXXX | Sleep | 148 | | NULL |
| 58 | application | 192.168.44.1:51968 | XXXXXXXX | Sleep | 11 | | NULL |
| 59 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+----+-------------+--------------------+----------+---------+------+-------+------------------+
You will see complete details of different connections. Now you can kill the sleeping connection as below:
mysql> kill 55;
Query OK, 0 rows affected (0.00 sec)
kill $queryID; is helpful but if there is only one query causing an issue;
Having a lot of MySQL sleeping processes can cause a huge spike in your CPU load or IO
Here is a simple one-line command (if behind the MySQL server is linux) which would kill all of the current sleeping MySQL processes:
for i in `mysql -e "show processlist" | awk '/Sleep/ {print $1}'` ; do mysql -e "KILL $i;"; done
This is only a temporary repair; I strongly advise identifying and addressing the problem's main cause.
For instance, you may set the wait timeout variable to the amount of time you want MySQL to hold open connections before shutting them.
But if the issue still persists and you have to investigate the DB queries that cause the problem there is another way. In screen session, you can use another while cycle to continuously kill the sleeping queries. (while there is an output of the mysql show processlit | grep -i sleep | awk id column and kill it.) If you are using MySQL replication between different hosts this will help them to catch up. So when using show slave status\G; Seconds_behind_master will be going to catch up.
Of course, you should investigate the root cause again.

mysql show processlist query shows state = null

I have a script running a batch of very similar queries.
All of them, except one, run without any problem.
Only one query is getting stuck.
In "show processlist" the query has state=null
According to docs, show processlist should report "State=null" only for the "show processlist" thread itself.
Server version: 5.0.67 MySQL Community Server (GPL)
mysql> show processlist;
+---------+--------+-----------+--------------+---------+------+-------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+--------+-----------+--------------+---------+------+-------+------------------------------------------------------------------------------------------------------+
| 3866613 | user | localhost | db_name | Query | 1986 | NULL | select log_time,log_action,log_action_id,log_object_id, #abcde:=if(log_action='abcde',to_ |
| 3873414 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+---------+--------+-----------+--------------+---------+------+-------+------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Could be a bug of your version of mysql, take a look at this bug for more information .

How to monitor Network traffic with MySQL?

ifconfig -output is somewhat messy thing to look at. When I saw the nice output below with the command (source), the question emerged:
Is there some more structured way, let say
MySQL, to look at ifconfig or similar data?
It would be cool, if I could monitor the network traffic in databases.
[prompt]$ mysqladmin -h localhost -u root -p processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 15 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
MySQL GUI Tools and administrator tools allow you to monitor to some extent. if you want raw packets, you can either use Ethereal or Wireshark