How does mysql.proc table get entries? - mysql

I want to know that in mysql when I create any procedure or function an entry for the corresponding create gets an entry in the mysql.proc table. I want to know by which process or trigger in mysql , It gets updated.
Thanks,
Nitesh Kumar

The tables in the mysql database aren't tables in the sense that your application tables are. Instead, they're internal mysql software data structures that happen to be made visible to the outside world as if they were tables.
So, the processes by which rows are made visible in those tables are entirely internal to the logic of mysqld.

Related

Operations between linked tables and native tables

I have three identical tables, one on MySQL, one linked to this one on Access by ODBC, and a native in the same Access database.
When I update the table on MySQL, the linked table on Access updates, and vice versa. But I would like to know if it is possible that the linked table updates the native table (and vice versa)?
Access table
MySQL table
It really depends on how the local Access table is being updated. If it is ALWAYS updated say by a few forms, then you could add a after update even to those few forms, and put in code to update the MySQL table.
Another approch (again you only/always update the local tables) is to add a table trigger to the local table. In this table code event, you can actually have it call some VBA code, and that VBA code could then update/insert to the linked MySQL table. Once again, then the two tables will automatic remain in sync.
The other possible would be to add a time + date stamp column to the tables (both on MySQL side, and on the Access side). You could then write some VBA code to sync up the tables. Such code is not too hard, but in a multi-user setting, this can become quite a challenge, since while you are syncing the data, other users might also update the MySQL tables and thus your sync routines might well miss some tables. Database sync software and this subject can fill a few books the size of medical texts, and is a VERY complex subject.
However, why not just always use linked tables to MySQL, and be done with any requirements to sync data? Access makes a great client to SQL server or MySQL. If you eliminate the local tables, then you eliminate the need to sync your data.

Replication of mysql table at runtime

I have a table in my MySQL for which I want to create a replica in some other database on the same MySQL instance with a different table name.
For eg
I have two database X and Y.
X contains a table by the name of A. Direct insertions takes place in this table only.
Y database will contain a table by the name of B which will contain the same data as of A.
MySQL version - 5.6
I have explored the options for copy of data. But this will not happen at runtime. I want a structure something like as soon as an insertion or updation takes place in table A, same data gets copied/updated to table B.
I also explored the option for the master-slave concept, in which it provides the copy to some other server. However, for this, a separate DB is needed but I want to be in the same DB instance.
I have no idea as to such a feature exists or not, or do I need to create such thing manually via code, or I have missed something in the above two ways which they can be modified and get the required result.
Can anyone please guide/help me with this problem? Thank you in advance.

How to achieve redundancy between 2 tables of different databases?

First of all I'd like to start saying that I've checked these two questions:
Sync 2 tables of different databases - MySQL
How to synchronize two tables of different databases on the same machine (MySql)
But while similar they are not what i need.
I have 2 databases in the same server.
Db1 and Db2
Both databases have the exact copy of a single table called "user":
userid
login
name
lastname
password
level
How can I achieve some sort of redundancy between these two tables in different databases?
If db1.user gets a new record then db2.user has to have that record, if a record is modified then the other one is modified and if deleted the then the other one gets deleted too.
To be more specific, db2.user needs to be a reflection of db1.user using triggers.
EDIT: there is this question: Mysql replication on single server and that is not even remotely close to what i want to do. I updated a little bit at the very end of what i previously posted with how I'd like to achieve this thanks to a suggestion.
As proposed you can use triggers as stated in this standard documentation.
You define AFTER INSERT,AFTER UPDATE and AFTER DELETE triggers on db1.user and within this trigger you have the NEW.object to pass the information into the db2.user table.

Mysql views return data when table empty

I am having a weird problem with mysql. I am developing a visual application on C# that stores data into a database. Previously I used SQL for the Database, but my client changed his mind for mysql. So I recreated the same schema on mysql. Now it is happening a really odd thing: My tables are completely empty, but when I execute the views, they return me back data from the old SQL tables, when I read directly from the tables they appear empty. The user that I use to connect are different and the most strange thing is that it happens even when I execute the view on mysql workbench. I have even truncated the tables in mysql and still the same thing. Does anybody know what may cause this anomaly and how to solve it?
p.s. Workbench version 6.2; Sql version SQL SERVER 2014
Regards.
In MySQL, a view is a virtual table based on the result-set of an SQL statement.
It contains rows and columns, just like a real table in your database. The fields in a view are fields from one or more real tables in the database.
When you execute the views, they return back data from the old SQL tables. It is because your view still contains the data you run a while ago. You have forgotten to Drop your View every time you execute it. To Drop a MySQL view, try this one:
DROP VIEW view_name
Views do NOT contain data of any kind -- except for Materialized Views and MySQL does not have those. If views had to be dropped and recreated every time a DML statement was executed on a table, views would be utterly useless.
The only time a view can return old data is when one process changes the contents of a table used in the view and the view is queried by another process before the first process commits the changes. You have not specified how the tables are being changed and how they are being queried. Nor have you included the create view statement. You could well be using other tables than what you think. This can happen during initial design of a database if tables are being slapped around like mad.

Setting up a master database to control the structure of other databases

I got a case where I have several databases running on the same server. There's one database for each client (company1, company2 etc). The structure of each of these databases should be identical with the same tables etc, but the data contained in each db will be different.
What I want to do is keep a master db that will contain no data, but manage the structure of all the other databases, meaning if I add, remove or alter any tables in the master db the changes will also be mirrored out to the other databases.
Example: If a table named Table1 is created in the master DB, the other databases (company1, company2 etc) will also get a table1.
Currently it is done by a script that monitors the database logs for changes made to the master database and running the same queries on each of the other databases. Looked into database replication, but from what I understand this will also bring along the data from the master database, which is not an option in this case.
Can I use some kind of logic against database schemas to do it?
So basicly what I'm asking here is:
How do I make this sync happen in the best possible way? Should I use a script monitoring the logs for changes or some other method?
How do I avoid existing data getting corrupted if a table is altered? (data getting removed if a table is dropped is okay)
Is syncing from a master database considered a good way to do what I wish (having an easy maintainable structure across several datbases)?
How will making updates like this affect the performance of the databases?
Hope my question was clear and that this is not a duplicate of some other thread. If more information and/or a better explantion of my problem is needed, let me know:)
You can get the list of tables for a given schema using:
select TABLE_NAME from information_schema.tables where TABLE_SCHEMA='<master table name>';
Use this list for a script or stored procedure ala:
create database if not exists <name>;
use <name>;
for each ( table_name in list )
create table if not exists <name>.table_name like <master_table>.table_name;
Now that Im thinking about it you might be able to put a trigger on the 'information_schema.tables' db that would call the 'create/maintain' script. Look for inserts and react accordingly.