mysql-multi: how to select instance by port (instead of socket)? - mysql

I have a second mysql instance running with mysqld_multi on port 3307. If connecting to it by port i get the databases from the first instance, like connecting to 3306. If i connect by socket i get the correct databases from the second instance. I need this second instance for a test environment, so i need to select the instance and it's storage/datadir by port. Can you help me?
my.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = something
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld2]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
socket = /var/lib/mysql2/tmp/mysql2.sock
port = 3307
pid-file = /var/run/mysqld/mysqld2.pid
datadir = /var/lib/mysql2
language = /usr/share/mysql/english
user = mysql
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
systemctl status mysqld
mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: active (running) since Mo 2016-02-08 12:54:40 CET; 24h ago
Process: 6901 ExecStartPost=/usr/bin/mysql-systemd-start post code=exited, status=0/SUCCESS)
Process: 6889 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 6900 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─6900 /bin/sh /usr/bin/mysqld_safe
└─7062 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
mysqld_multi report
WARNING: Log file disabled. Maybe directory or file isn't writable?
mysqld_multi log file version 2.16; run: Di Feb 9 13:54:19 2016
Reporting MySQL servers
MySQL server from group: mysqld2 is running
Connect to first instance
$ mysql -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| portal |
| swfl |
+--------------------+
9 rows in set (0,00 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
Connect to second instance by port
$ mysql -P 3307 -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| portal |
| swfl |
+--------------------+
9 rows in set (0,00 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
Connect to second instance by socket
$ mysql -S /var/lib/mysql2/tmp/mysql2.sock -u root -p
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3307 |
+---------------+-------+
1 row in set (0,00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tmp |
+--------------------+
4 rows in set (0,00 sec)
Server
CentOS 7 with MySQL 5.6.25

Related

Time zone in Linux and in MySQL 8.0

I am trying to set the time zone in MySQL so that it matches the Ubuntu 20.04 time zone. When I check the error.log for MySQL I see a different set of data for the time zone.
Here is what I have from the system, MySQL 8.0.23 and the error.log:
sudo nano /etc/mysql/my.cnf
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
default-time-zone = "SYSTEM"
Console commands:
date
Sat 01 Jan 2022 10:01:29 PM EST
var/log/mysql/error.log
2022-01-02T02:31:15.751387Z 0 [System] [MY-010931] [Server]
mysql
mysql> SELECT NOW();
+---------------------+
| NOW() |
+---------------------+
| 2022-01-01 22:04:43 |
+---------------------+
1 row in set (0.00 sec)
mysql> SELECT ##global.time_zone;
+--------------------+
| ##global.time_zone |
+--------------------+
| SYSTEM |
+--------------------+
1 row in set (0.00 sec)
After further research I found what I was looking for in the post at stackoverflow.com/questions/35123049/… this change did the trick:
[mysqld]
log_timestamps = SYSTEM

AWS unable to see RDS mysql DB after connecting via mysql

Stupid question maybe but for some reasons, i am unable to see my RDS mysql db instance after connecting via mysql from my ec2 instance. The EC2 and the RDS security groups have the 3306 port open between them, no issues. The database is already created as i can see it on the RDS console.
mysql -h RDS endpoint -P 3306 -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| innodb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
Regards,
Ochen

Grafana selecting data from MySql always gives Command Denied Error 1142

I'm trying to use grafana with mysql. MySql is getting data from wordpres. I can connect to the MySql database with grafana but any attempt to query the database results in a permission error quoted below. Does anyone know what I'm doing wrong? I made sure to FLUSH PRIVILEGES; when creating this account.
What account is being used?
mysql> SELECT USER(),CURRENT_USER();
+-------------------+-------------------+
| USER() | CURRENT_USER() |
+-------------------+-------------------+
| grafana#localhost | grafana#localhost |
+-------------------+-------------------+
1 row in set (0.00 sec)
What permissions does the account have?
mysql> show grants for 'grafana'#'localhost';
+------------------------------------------------------------------------+
| Grants for grafana#localhost |
+------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'grafana'#'localhost' WITH GRANT OPTION |
+------------------------------------------------------------------------+
1 row in set (0.00 sec)
Can I select from a table? (Yes)
mysql> select * from wp_users;
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
| ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
| 1 | admin | ********************************** | admin | a.guy#place.com | | 2019-02-22 18:09:58 | | 0 | something |
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
1 row in set (0.00 sec)
What is my mysql info?
mysql> status
--------------
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Connection id: 42787
Current database: information_schema
Current user: root#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: utf8
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 43 days 2 hours 29 min 53 sec
Threads: 3 Questions: 3576291 Slow queries: 0 Opens: 1570 Flush tables: 1 Open tables: 692 Queries per second avg: 0.960
--------------
What query am a trying to run in grafana?
SELECT
user_registered,
user_login
FROM wp_users
I tried with with and without a trailing ; - no change.
What does grafana give back to me with this query?
Error 1142: SELECT command denied to user 'grafana'#'localhost' for table 'wp_users'
I realize that this account has too many permissions, but seeing as grafana thinks it doesn't have enough, for now I'm trying to get it to work with at least more than it needs.
After being stumped by this for a few hours, the notion of looking at logs was suggested to me. Since MySql doesn't have logs enabled by default, I changed the settings to enable the logs and restarted MySql. After doing this everything worked fine. It seems all I had to do was to restart the service.
The solution:
sudo service mysql restart

MariaDB on Docker Linux have two different version between external/internal IP

I ran MariaDB as Docker - expose port 3306 to localhost:3307
Connect Database via localhost:3307
$ mysql -u tvgift -P 3307 -h localhost -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
Connect Database via 172.18.0.2:3306 (IP I got from $ docker inspect <docker ID>
$ mysql -u tvgift -P 3306 -h 172.18.0.2 -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set (0.00 sec)
I tried another client (Using mycli) with both IP, result is same.
$ mycli mysql://tvgift:tvgift#localhost:3307/tvgift
mariadb tvgift#localhost:tvgift> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set
Time: 0.013s
$ mycli mysql://tvgift:tvgift#172.18.0.2:3306/tvgift
mariadb tvgift#172.18.0.2:tvgift> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set
Time: 0.013s
So, only mysql client have differ between two IP of one container service, can you tell me why?
localhost != any IP address. That is,
GRANT ... TO tvgift#'%' ...
does not include
GRANT ... TO tvgift#'localhost' ...
If you want to connect both via localhost and via an IP address or hostname, you must provide two GRANTs with the same permissions (such as ON tvgift.*).

PhpStorm MySQL connection timeout

I use PhpStorm 2016.3.2 and I want to connect my MySQL database.
But, when I want to connect, I have a timeout exception.
I checked the connection hots/port :
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
mysql> show processlist;
+-----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+------+---------+------+----------+------------------+
| 287 | root | localhost | NULL | Query | 0 | starting | show processlist |
+-----+------+-----------+------+---------+------+----------+------------------+
1 row in set (0,00 sec)
mysql>
I have download jdbc connector/j here and copy/past the mysql-connector-java-5.1.40-bin.jar file in /Library/Java/Extensions. I have add this file to my PhpStorm MySQL Driver :
My Database connection config :
I do not understand why he can not connect...