Amazon RDS have different global values on similar host - mysql

I have 2 database on two different RDS hosts using a similar group. Most of the mysql global variables are same except for binlog_format and log_bin. As these are not configured within parameter groups, I am not sure why they are different for different database host.
Mysql version is 5.5
Mysql Property host1 host2
-------------- ----- ---------
binlog_format MIXED STATEMENT
log_bin ON OFF
Kindly guide where to look for.
Thanks

Related

Increase MySQL max_connection on Lightsail (not RDS) database

I have a database created in Lightsail (not RDS, just Lightsail>Databases>Create database). I am trying to increase its max_connections number from 150 to 500 by connecting to it remotely, but I am getting the following error:
Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
Is there a way for me to achieve this on Lightsail?
Database instance info:
High availability MySQL database (8.0.11)
2 GB RAM
1 vCPU
80 GB SSD
It sound like you are attempting to set the parameter through SQL?
For lightsail databases, you need to follow these instructions and use AWS CLI: https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-updating-database-parameters
(if I'm wrong, please let us know what command you are running to generate the error you are seeing above)
AWS RDS and lighsail wil automatically inject your proper amount of max_connections based on your memory installed. With 2 gigs, you get around 66*2=132
It will just overwhelm even RDS if you make too many connections, as they require more RAM for each one.
"parameterName": "max_connections",
"parameterValue": "{DBInstanceClassMemory/12582880}"
mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 66 |
+-----------------+-------+
# pip3 install awscli --upgrade --user
# .local/bin/aws lightsail get-relational-database-parameters --relational-database-name <your given name>
# .local/bin/aws lightsail update-relational-database-parameters --relational-database-name <your given name> --parameters "parameterName=explicit_defaults_for_timestamp,parameterValue=0,applyMethod=pending-reboot"
which is required for MySQL 5.7
OR for your situation
# .local/bin/aws lightsail update-relational-database-parameters --relational-database-name <your given name> --parameters "parameterName=max_connections,parameterValue=500,applyMethod=pending-reboot"
If your region is us-west-2a, then remove the "a" from the .aws/config
[default]
region = us-west-2
output = json

How can I pass command-line arguments when creating a new Database connection in SQLPro?

When I start my MySQL client from the command-line, I do the following:
$ mysql -u root -p -h 127.0.0.1 --init-command="SET SESSION wait_timeout=300"
I set the session wait_timeout to 300 seconds for security purposes. If there is no database activity for 5 minutes, I want the connection to be killed so that it is not actively left open for long periods of time which is a security risk.
However, I really prefer using the Mac desktop application SequelPro to access the database instead of the command-line shell. It's my bread-and-butter. I absolutely love it. Here's what it looks like when I open a DB connection in SequelPro:
So how can I give SequelPro the same `--init-common argument I gave on the command-line above? Or is there any other way for me to achieve the security goal I'm trying for?
If you want to make this global setting for everyone connecting from any tool. You add this to the configuration file, my.cnf (if you're running MySQL on Unix-based OSs) or my.ini (if you're running MySQL on Windows-based OSs).
This is from MySQL documentation about wait_timeout
The number of seconds the server waits for activity on a
noninteractive connection before closing it.
On thread startup, the session wait_timeout value is initialized from
the global wait_timeout value or from the global interactive_timeout
value, depending on the type of client (as defined by the
CLIENT_INTERACTIVE connect option to mysql_real_connect()). See also
interactive_timeout.
So, set this global parameter in [mysqld] section of your configuration file to keep your security in check.
[mysqld]
interactive_timeout=300
wait_timeout=300

cannot find mysql slow query log file on mac

I am trying to enable slow_query_log on mysql, but I could not find it on my mac.
I read in MySQL 5.7 Documentation that"
By default, the server writes files for all enabled logs in the data directory.
When I write show variables like '%slow_query%'; in mysql shell, I see the following:
but I can't see McBook-Pro-6-slow.log in the data directory. Here is all I can see in the data directory:
Could someone let me know why I can't see the slow log file?
In order to enable the slow_query_log, I've read here that I should add slow-query-log=1 to my.cnf. Here, my problem is that I am not sure where is mysql config file on my Mac. I've found a my-default.cnf in usr/local/mysql/support-files/ and another my.cnf file in /etc. Which one should I modify??
Thanks,
Refer to this Stackoverflow question MySQL 'my.cnf' location? which pertains to Mac OS. As you can see the permutations of locations are numerous usually compounded by different distros and MAMP XAMP WAMP bundles and Home Brew. It is not uncommon to have 2 mysql daemons on a box and not even know it.
Which is why in comments I suggested looking at the output of select ##basedir for the location of the my.ini (Windows) or my.cnf (Linux/Mac). That is not to suggest a configuration file is going to be there, but that is where it should be if one were to exist. Without it, baked-in default values are used. Often there is a stub, a suggested file, named differently (like my-default), awaiting your tweaks and a rename or copy to the appropriate file name of my.ini or my.cnf.
There is also a system variable named slow_query_log_file and its value visible if set thru SELECT ##slow_query_log_file;. For me right now it has a value of GUYSMILEY-slow.log because I did not set it in my ini (Windows) and it defaults to computername+"-slow.log".
That is the filename without the path. Where the file actually is written to is in the datadir seen with the output of select ##datadir;.
On my system this means (via ##basedir)
C:\Program Files\MySQL\MySQL Server 5.6\my.ini
would have a setting that ends up in a slowlog file written to in this absolute path (helped by ##datadir):
C:\ProgramData\MySQL\MySQL Server 5.6\data\GUYSMILEY-slow.log
and a fragment inside that log file might show something like this:
Ini and cnf changes require a MySQL daemon restart. In that configuration file a section similar to (my 5.6)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.6\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.6\\Data\\
port=3306
log_warnings = 2
and (my 5.7)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.7\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Data\\
port=3307
log_error_verbosity=2
the above is used within the [mysqld] section to play with settings. What I suggest is playing with this section with an innocuous setting like log_error_verbosity (5.7.2 and up) or similar, save it. Restart the deamon and determine if the variable (as Rick James would call settings because most really aren't dynamically settable). So a sanity check of select ##log_error_verbosity (5.7.2 and up) can confirm it the change is picked up. If it is, bingo, you are doing it right.
The Manual Page Server System Variables depicts the variables (settings) and whether or not they can be dynamically set/changed after the config file load via commands. Dynamic changes are reverted upon daemon restart.
How one would dynamically change a variable might look like:
SET GLOBAL log_error_verbosity=2;
Again, only certain variables are available in certain MySQL versions, such as the above, not available in older versions.
Also note multiple versions of MySQL running concurrently on a server. On mine i have 5.6.31 and 5.7.14. To access a different one via command line tools, use something like the -P 3307 switch to point at the one running on port 3307. Note the uppercase P as opposed to lowercase (which would mean prompt for password).
Determine if multiple instances are running. I use port checks such as
sudo netstat -tulpn (Linux)
netstat -aon | more (Windows, the top part, State=LISTENING)
Unfortunately these types of changes and trial and error take time and are very frustrating. Sorry I do not have a quick and easy answer for all cases.
Addendum
Notes here related to comments. In the below, w-x-y-z is a redacted IP Address.
On a Linux box (amazon ec2 redhat btw):
select ##slow_query_log;
-- 0 (so it is turned off)
SELECT ##slow_query_log_file;
-- /var/lib/mysql/ip-w-x-y-z-slow.log
select ##version;
-- 5.7.14
set global slow_query_log=1;
Error Code: 1227. Access denied; you need (at least one of) the SUPER privilege(s) for this operation 0.094 sec
(ok I was in MySQL Workbench as a dummied down user, off to do it as root via MySQL cmd line ...
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> select ##slow_query_log;
+------------------+
| ##slow_query_log |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
btw Workbench user can confirm the above `1`
at shell as linux user:
[ec2-user#ip-w-x-y-z ~]$ cd /var/lib/mysql
[ec2-user#ip-w-x-y-z mysql]$ sudo ls -la
(there were many files, only one needed to show you below)
-rw-r-----. 1 mysql mysql 179 Sep 19 01:47 ip-w-x-y-z-slow.log
[ec2-user#ip-w-x-y-z mysql]$ sudo vi ip-w-x-y-z-slow.log
(Header stub, the entire contents, no slow queries yet, log seen below):
/usr/sbin/mysqld, Version: 5.7.14 (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
Time Id Command Argument
SHOW VARIABLES LIKE 'log_output'; to verify that it is set to FILE or FILE,TABLE.

What is the correct location of mysql.sock file on linux

I have a mysql.sock file located at:
/tmp/mysql.sock
But the my.cnf is pointing to this location:
socket=/var/lib/mysql/mysql.sock
Is this correct?
The socket declaration should be located under [mysqld] in your my.cnf. If you have declared it there and still pointing to another place such as tmp, then your my.cnf file that you have been editing is not being read when mysql starts or there is another my.cnf overriding the one you have been editing. The case may also be that there is a second Socket declaration in the same my.cnf file that is overriding the one you expect to be read at start by mysql.
You can check its absolute path by logging into mysql and running:
mysql> show variables like 'socket';
+-----------------------------------------+-------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------+
| socket | /yourpath/mysql.sock |
+-----------------------------------------+-------------------------------+
1 rows in set (0.00 sec)
There is no right or wrong place on linux for saving sockets, except on external devices which are unmounted at any time or folders which are emptied from time to time. You need to configure where you want to place it.
For the MySQL console client there is something more to consider: The client seems to use the socket configuration value provided in [client] instead of [mysqld]. If you have a multiple MySQL server setup like i have (4.1, 5.5, 5.7), you probably want to use a "--defaults-extra-file" option with the socket written in the [client] part for each different server. The socket needs to be the same as the one defined in the my.cnf [mysqld] part used on the server.
Here is an example defaults-extra-file.cnf, remember to change the user, password and socket to your needs - and keep it on access rights 400 (there is a password stored after all):
[client]
user = guardian
password = I-4m.Gr00t!
host = localhost
socket = /var/run/mysqld/mysqld-5.6.sock
This only applies though if you are using "localhost" as the value for "host". If you have multiple local addresses (127.0.0.2, 127.0.0.3), you need to leave the config variable for "host" on "localhost" to use the configured socket. Otherwise the client will connect to the server using TCP.
This was tested on my Debian 9.5 Server with MySQL 4.1.22, 5.5.49 and 5.7.19 and their respective clients.

Does mySQL Replication: Master DB Name has to be the same as the Slave DB name?

I have set the Master DB Name as MDB & in the Slave server I set to replicate-do-db=SDB <-- this did not work? But when I set it up as the same DB name it works. Is there any solution out there to setup 1 master db with 2 different slaves but in the same server??
You need to specify the replicate-rewrite-db option:
--replicate-rewrite-db=from_name->to_name
Tells the slave to translate the default database (that is, the one
selected by USE) to to_name if it was from_name on the master. Only
statements involving tables are affected (not statements such as
CREATE DATABASE, DROP DATABASE, and ALTER DATABASE), and only if
from_name is the default database on the master. This does not work
for cross-database updates. To specify multiple rewrites, use this
option multiple times. The server uses the first one with a from_name
value that matches. The database name translation is done before the
--replicate-* rules are tested.
If you are only replicating certain databases, you will need to specify the replicate-do-db. Note that the argument to this is the name of the database after the rename operation applied by replicate-rewrite-db:
--replicate-do-db=db_name
MySQL Replication with different database names
Add the following to the logging and replication section of your MySQL configuration file (/etc/mysql/my.cnf), I inserted mine right above relay-log.
replicate-rewrite-db = db_1->db_2
Replace db_1 with the database's name being replicated from the remote master and db_2 with the destination database's name.
Restart the MySQL server (/etc/init.d/mysql restart)
Access the MySQL shell (mysql -h localhost -u root -p)
Check the Slave status (SHOW SLAVE STATUS\G)