In MySQL DB server we have schema named test. The schema has table named users.
The table users not used in any place by rails application. The only place the entry for users found is in schema.rb.
The users tables has some data stored and data gets inserted by another java application which runs on some other server. The rails application makes API call to JAVA application via HTTPs and retrieves the data for usage if needed.
Daily the MySQL Master DB gets replicated to Slave server.
During replication the bellow query getting logged in slow logs and its making replication lag.
root localhost test Query 93 Sending data SELECT /*!40001 SQL_NO_CACHE */ * FROM `users`
root localhost test Query 62 Writing to net SELECT /*!40001 SQL_NO_CACHE */ * FROM `users`
This query is not fired from Rails application - we can see the user and host of the connection in logs is root and localhost.
I would be very grateful if someone helps me to identify origin of the query and how can or what can be done to avoid query.
I had the same problem. In my case it was due to calling mysqldump.
Related
I am trying to display audit logs for Cloud-SQL in the stack-driver-console. I have already enabled audit-log for Cloud-SQL in IAM.
I connect to mysql or postgres databases in Cloud-SQL and when I connect these audit logs are displayed in the console.
request: {
#type: "type.googleapis.com/google.cloud.sql.v1beta4.SqlInstancesGetRequest"
instance: "testpostgres"
But after this if I perform any operation in that particular database like SELECT or INSERT or DELETE, there is no audit-log (data-access) generated for both mysql and postgres. In mysql instance I have set the following database flags:
audit_log ON (this is in beta version)
For mysql if I add 1 more flag **general_log** I am able to get those DML statements but they come under a different log **cloudsql.googleapis.com%2Fmysql-general.log** and don't come under audit-logs
Similarly for postgres these statements come under a different log:
**cloudsql.googleapis.com%2Fpostgres.log**
I am new to this Cloud-SQL so not aware of the logging implemented there. Why no audit logs are generated when any DML is done for the particular database in that Cloud-SQL instance and should I set any other flag for this purpose?
DML are not logged on the audit logs by default on Cloud SQL. To see the DML logs in Logging, you need use pgAudit on your PostgreSQL. By the way pgAudit is only available in PostgreSQL instances.
Steps to enable pgaudit:
Enable pgaudit using gcloud command
gcloud sql instances patch [INSTANCE_NAME] --database-flags \ cloudsql.enable_pgaudit=on,pgaudit.log=all
Create the pgaudit extension in your postgres database
CREATE EXTENSION pgaudit;
Run a simple select statement on your postgres database
Query DML statements logs in Logging:
Open Logging -> Logs Explorer
In the query builder apply this filter:
resource.type="cloudsql_database" logName="projects/<your-project-name>/logs/cloudaudit.googleapis.com%2Fdata_access" protoPayload.request.#type="type.googleapis.com/google.cloud.sql.audit.v1.PgAuditEntry"
I used the quickstart for PostgresSQL for testing.
Query postgre database:
Filter Logging using the filter above:
I have an application which connects and stores data on a MySQL database, I need to connect and retrieve this data in a view from another application which uses an SQL Server Database. My attempt to handle this was to create a linked server that connects to the MySQL Server in SQL Server.
That seems to have worked, all connections have passed and if I run the following queries
SELECT * FROM MYSQLLINK...table1` or `SELECT * FROM OPENQUERY(MYSQLLINK, 'SELECT * FROM table1')
I get results.
Problem
The problem is, I want to create a view which joins quite a few reference tables ( I actually have 20 joins but it's joining the same table because it's a big reference table.)
but on execution on the SELECT or CREATE VIEW I get the following error.
OLE DB provider "MSDASQL" for linked server "MYSQLLINK" returned
message "[MySQL][ODBC 5.1 Driver]Lost connection to MySQL server at
'waiting for initial communication packet', system error: 10060".
Msg 7303, Level 16, State 1, Line 4
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQLLINK".
Completion time: 2020-01-19T22:00:00.1759949-04:00
I am unsure why this is occurring, would appreciate if any could assist in figuring this out and helping in mitigating this error that will allow my view to be created and queried.
I've noticed if I comment out 85% of the joins the query does not fail. Where would I increase this time out the tome that is mentioned?
I should also mention that the MySQL is on an AWS server while the SQL Server is on my localhost.
I couldn't recreate the failure test case on my local-end, but what you mentioned directs us to following pointers:
Your linked server connection is getting timeout (probably)
Potential reason for timeout could be the high response time of query (view which joins quite a few reference tables)
What about changing the approach:
Can you create the view on MySQL rather than on SQL Server?
Is materialization of the result of the view is an option?
Or alternatively, what about writing a stored procedure on SQL Server-end and sequentially join your tables one-at-a-time (or as-many-reasonable-at-a-time) with use of temporary tables to store intermediate results?
I've seen several instances across the web of a people running a SQL query in phpmyadmin and experiencing the loading screen, but it never retrieving information. I'm experiencing a similar issue and have been unable to find any solution.
Here's the query:
SELECT Comments.device_id, Comments.Author, Comments.Ack_type,
Comments.Entry_Time, Comments.Comment_ID, Comments.Comment,
History.datetime, History.device_status, History.status_name
FROM `Comments` LEFT JOIN History ON Comments.device_id = History.device_id
GROUP BY device_id
Here are the issues:
My apache2 and mysql error logs don't return any information. The Chrome console produces no errors for the elements on the page It just says loading.
No Chrome Errors
The phpmyadmin console doesn't error out but instead loads and locks down phpmyadmin
phpmyadmin loading
Fails to ever return any information from the query.
Things to note:
Simple queries work and wrong queries produce error codes.
In order to get phpmyadmin running properly again after running this query I have to either clear my cookies, restart my web browser, or restart mysql on the server side.
Here's the server information:
Server: Localhost via UNIX socket
Server type: MySQL Server version:5.7.23-0ubuntu0.16.04.1 - (Ubuntu)
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
Here are the table structures:
table structures
Try changing GROUP BY device_id to GROUP BY Comments.device_id
Try adding LIMIT 1 to see if there is too many records
I have a setup of 12 download servers, they all have their ip and login details in a mysql database on my database server.
The database has a dlserver_details table with following fields:
id, server name, location, domain, ip address, additional ips
Each row in this table has a specific server's records.
How do I find out which server is connecting to the mysql so that mysql can send the correct server's information?
For example if Server A is connecting to mysql through remote sql, there is no way of knowing which row belongs to Server A.
The solution I came up with 4 years ago was to assign each server an id manually and save it in a file called config.php
When the server wants to fetch its details from the mysql db, it sends query like:
$serverid = 4;
SELECT * from dlserver_details where id = $serverid
Which works perfectly fine.
But the problem is that this solution is not very efficient as we are scaling up. Whenever we add servers to the cluster, we have to modify some files and the database. This slows things down as the files are synced automatically to all the download servers then I have to manually assign the correct server id and update its records in the database.
Is there a proper solution to this? Like Can I track with mysql which host is connecting to it for the query so that it can look for the correct record for that host on its own?
Something like:
lets say mysql ip is 1.1.1.1 and client server ip is 2.2.2.2
row in the table:
id = 4
ip = 2.2.2.2
servername = Server A
Query: SELECT * FROM dlserver_details WHERE ip = CONNECTING_HOST_IP
Would that work?
Ended up doing it with:
... WHERE ip = (Select SUBSTRING_INDEX(host, ':', 1) From information_schema.processlist WHERE ID = connection_id())
I am working on a remote development server. I have the mysql host name, db name, user name , password of that remote server. I want to setup/replicate/map that dev server mysql in my local phpmyadmin, so that I can access the remote server db locally(for ex :- /mylocalip/remote-server-db).
Thus I don't have to do ssh connection and open the mysql in terminal. How can we do this in phpmyadmin/config.inc.php.
Let me explain again through an example. Lets say the remote server db is accessible through 213.81.203.130/phpmyadmin. I want to access that db from my local ip through an alias name by creating a mapping i.e 192.168.10.140/remote-db. Basically this can be done by adding some sort of code in phpmyadmin/config.inc.php or config.db.php. But how to do it I am not sure.
If you want to avoid using terminal, why not try MySQL Workbench to connect to the database?
UPDATE
In light of all the views to this question, I am adding a solution that more accurately matches the question. Please see this link, I believe it will be helpful. It involves editing the phpmyadmin config.inc.php file to add additional servers. This is how you can keep your localhost connection, and add any remote db connections. Simply select the server from the drop down at the login screen to phpmyadmin.
There are 3 methods to set this up
METHOD #1 : MySQL Replication
Setup MySQL Replication where the Slave has this option
replicate_do_table=mydb.mytable
Then, any DML (INSERT, UPDATE, DELETE) or DDL (ALTER TABLE) you execute will go immediately to serverB. This makes Method #1 is the fastest and most granular approach.
METHOD #2 : Copying the table to the other server
Rather than rehash, Here is an earlier post, Mr. RolandoMySQLDBA did May 31, 2011 for this method : [How do you copy a table from MySqlServer_A to MySqlServer_B?][1]
METHOD #3 : FEDERATED Table (MyISAM Only)
Suppose mytable on serverA looks like this
CREATE TABLE mydb.mytable ( ... ) ENGINE=MyISAM;
You can a mapping of the target table in serverB by running this on serverA like this
CREATE TABLE mydb.mytable_remote LIKE mytable; ALTER TABLE
mydb.mytable_remote ENGINE=FEDERATED
CONNECTION='mysql://username:password#serverB/mydb/mytable';