How to use "central columns" in phpmyadmin? - mysql

PMA has the tools for adding the central columns. As far as I understand, it's used with foreign constraints. I have two tables: TableA and TableB.
Structure of TableA: id_of_A, name_of_A_value, ...
Structure of TableB: id_of_B, foreign_id_of_A,... and foreign constraint from foreign_id_of_A to A-table.id_of_A.
And it's very difficult to select needed foreign_id_of_A while insert new row into TableB because only value of id_of_A is visible. Could central columns help me with this problem? How central column works?

Central Column
You can add/remove columns to the list as per your requirement. These columns in the central list will be available to use while you create a new column for a table or create a table itself. You can select a column from central list while creating a new column, it will save you from writing the same column definition over again or from writing different names for similar column.
To allow the usage of this functionality:
set up $cfg['Servers'][$i]['pmadb'] and the phpMyAdmin configuration
storage
put the table name in $cfg['Servers'][$i]['central_columns'] (e.g. pma__central_columns)
This feature can be disabled by setting the configuration to false.

Perhaps the feature that you are looking for is the "Display Column" under "Relation View" in the table structure view. This allows you to choose what column is shown in the PHPMyAdmin interface regardless of what is stored in the database foreign key constraint.
If the line is not shown than you need to enable the feature in PHPMyAdmin. See the FAQ Entry and relevant configuration option entries: $cfg["servers"][$i]["relation"] and $cfg["servers"][$i]["table_info"] (in the previous link, at the time of posting (I don't have enough reputation to post more than 2 links)).
Essentially you create a couple of tables in a database that PHPMyAdmin can use to store additional data and then tell it which tables these are. Once this is done PHPMyAdmin will let you choose which columns to display (on mouse over of the linked column, and while editing data). If you installed it on a Linux distribution via a package manager it should have already created these tables for you (or at least asked you if you wanted to), if it did not, re-installing the package may help. I don't have any experience with installing it on Windows or Mac OS X, but I would presume that there is some automated method of creating these tables for those platforms.
(On Debian and Debian-based Linux Distributions (such as Ubuntu), the extra database is configured with db-config-common. If it was not configured at install time, dpkg-reconfigure phpmyadmin will allow you to set up the database (please note that this might destroy some user/system preferences in PHPMyAdmin).)

I've found here is an exhaustive description:
As the name suggests, the Central columns feature enables to maintain a central list of columns per database to avoid similar name for the same data element and bring consistency of data type for the same data element. You can use the central list of columns to add an element to any table structure in that database which will save from writing similar column name and column definition.
To add a column to central list, go to table structure page, check the columns you want to include and then simply click on “Add to central columns”. If you want to add all unique columns from more than one table from a database then go to database structure page, check the tables you want to include and then select “Add columns to central list”.
To remove a column from central list, go to Table structure page, check the columns you want to remove and then simply click on “Remove from central columns”. If you want to remove all columns from more than one tables from a database then go to database structure page, check the tables you want to include and then select “Remove columns from central list”.
To view and manage the central list, select the database you want to manage central columns for then from the top menu click on “Central columns”. You will be taken to a page where you will have options to edit, delete or add new columns to central list.
http://lees.geo.msu.edu/phpmyadmin/doc/html/faq.html
May be it's useful for foreign constraints modelling, but absolutly useless in usage. I'm still looking for a solution for adding value into one table by the ID from another table so that it was understandable for people, not for computers. If you know how to do that, let me know.

Related

Should I use multiple databases in MySQL for my "hosting" platform? [duplicate]

Let us say I need to design a database which will host data for multiple companies. Now for security and admin purposes I need to make sure that the data for different companies is properly isolated but I also do not want to start 10 mysql processes for hosting the data for 10 companies on 10 different servers. What are the best ways to do this with the mysql database.
There are several approaches to multi-tenant databases. For discussion, they're usually broken into three categories.
One database per tenant.
Shared database, one schema per
tenant.
Shared database, shared schema. A tenant identifier (tenant key) associates every row with the right tenant.
MSDN has a good article on the pros and cons of each design, and examples of implementations.
Microsoft has apparently taken down the pages I referred to, but they are on on archive.org. Links have been changed to point there.
For reference, this is the original link for the second article
In MySQL I prefer to use a single database for all tenants. I restrict access to the data by using a separate database user for each tenant that only has access to views that only show rows that belong to that tenant.
This can be done by:
Add a tenant_id column to every table
Use a trigger to populate the tenant_id with the current database username on insert
Create a view for each table where tenant_id = current_database_username
Only use the views in your application
Connect to the database using the tenant specific username
I've fully documented this in a blog post:
https://opensource.io/it/mysql-multi-tenant/
The simple way is: for each shared table, add a column says SEGMENT_ID. Assigned proper SEGMENT_ID to each customer. Then create views for each customer base on the SEGMENT_ID, These views will keep data separated from each customers. With this method, information can be shared, make it simple for both operation & development (stored procedure can also be shared) simple.
Assuming you'd run one MySQL database on a single MySQL instance - there are several ways how to distinguish between what's belonging to whom.
Most obvious choice (for me at least) would be creating a composite primary key such as:
CREATE TABLE some_table (
id int unsigned not null auto_increment,
companyId int unsigned not null,
..
..
..,
primary key(id, company_id)
) engine = innodb;
and then distinguishing between companies by changing the companyId part of the primary key.
That way you can have all the data of all the companies in the same table / database and at application level you can control what company is tied to which companyId and determine which data to display for certain company.
If this wasn't what you were looking for - my apologies for misunderstanding your question.
Have you considered creating a different schema for each company?
You should try to define more precisely what you want to achieve, though.
If you want to make sure that an HW failure doesn't compromise data for more than one company, for example, you have to create different instances and run them on different nodes.
If you want to make sure that someone from company A cannot see data that belong to company B you can do that at the application level as per Matthew PK answer, for example
If you want to be sure that someone who manages to compromise the security and run arbitrary SQL against the DB you need something more robust than that, though.
If you want to be able to backup data independently so that you can safely backup Company C on mondays and Company A on sundays and be able to restore just company C then, again, a purely application-based solution won't help.
Given a specific DB User, you could give a user membership to group(s) indicating the companies whose data they are permitted to access.
I presume you're going to have a Companies table, so just create a one-to-many relationship between Companies and MySQLUsers or something similar.
Then, as a condition of all your queries, just match the CompanyID based on the UserID
in my file Generate_multiTanentMysql.php i do all steps with PHP script
https://github.com/ziedtuihri/SaaS_Application
A Solution Design Pattern :
Creating a database user for each tenant
Renaming every table to a different and unique name (e.g. using a prefix ‘someprefix_’)
Adding a text column called ‘id_tenant’ to every table to store the name of the tenant the row belongs to
Creating a trigger for each table to automatically store the current database username to the id_tenant column before inserting a new row
Creating a view for each table with the original table name with all the columns except id_tenant. The view will only return rows where (id_tenant = current_database_username)
Only grant permission to the views (not tables) to each tenant’s database user
Then, the only part of the application that needs to change is the database connection logic. When someone connects to the SaaS, the application would need to:
Connect to the database as that tenant-specific username

MySQL Workbench - adding relations without having to edit the tables

I am editing a schema in MySQL workbench. I imported the schema from a mysqldump. Since it doesn't include any foreign keys, I am adding the relationships manually.
Here is my problem: When adding a relationship, workbench adds a column with the foreign key to one of the tables. However, the column is already present. I have to remove the current column and change the name of the new column to the name of the original column.
I illustrated it in the attached pictures:
The two original tables
The two tables after adding the relationship
After removing original column and renaming new column - this is what I want in one step
Is there a way to avoid this, and choose the target-column when adding the relationship, so that I don't have to edit a larger number of tables?
(Edited to add: The example tables are not the tables I want to connect, in case somebody recognizes the Drupal 8 tables - they were just short enough to aid as an example).
Most of the relationship commands automatically create columns to host the new relationship. However, there's one tool that allows to select existing columns for a 1:n relationship. See in the tools toolbar. The last icon contains a picker symbol. This is the one to use. For quick access simply press '6'.

MySQL database merge of two databases

I set up two Wordpress blogs a while ago, both obviously having different databases. I've more recently merged these databases into one by changing the tables prefixes, therefore these two 'entities' have the same amount of tables and the same names (as they originate from a Wordpress install) but with different prefixes, i.e.:
Blog1_tabledata1
Blog1_tabledata2
Blog1_tabledata3
Blog1_tabledata4
Blog2_tabledata1
Blog2_tabledata2
Blog2_tabledata3
Blog2_tabledata4
I have now realised that I need to merge these two databases (where they're both using the same tables) so that they can be used in the same Wordpress instance (later separated by tags etc).
What would be the most simple way of doing this?
(Please note I am asking this from a MySQL standpoint - this is not a Wordpress question!)
If you absolutely are not looking for a wordpress solution, that means you are not looking at all domains. By this, I mean that you are not looking at what the data means. This could be a problem. but nevertheless:
figure out the foreign keys. If the tables are MyIsam instead of InnoDB, they will be implicit. Figure out what ID points to what field.
select from one DB and insert into the other. This mean you add the rows of one table to the equivalent of the target database. Auto-increment rows will be fine. But for foreign key (explicit AND implicit) fields here is were the trouble starts.
If you insert, say a user, the user gets a new ID -> You have to find the equivalent of the userid in the old db so you can insert the foreign keys with the right ID. this is tricky and without making this a wordpress-question there is no more help we can give you: just figure out what rows they should be :). it is database // domain specific. (with that I mean you can't just figure that out by looking at the fields, you must know some of what they mean)
If the db is correct, this should work, but I'm not sure if you get into trouble with duplicates (all should go on ID, and you fixed that in step 3 with unique and connected id's. but if your domain doesn't want two accounts, two pages or two whatevers (tags?) to have the same name, you still have a problem. But again, this is domain specific logic and you're specifically asking not to go there.

How to set column to be linked in an imported data list in Sharepoint 2010?

I have an Access database with 1800 records, when moved to Sharepoint list, it randomly sets the linked column,
For example: I have the following columns:
"Badge No.", "Name" and "File status".
Every time when move it (import) to Sharepoint list, it sets "File status" to be linked to the item.
How to set the column "Name" to be linked to the item ?
It not quite clear here, but you do seem to be suggesting that you have more than one table involved here. If you going to send tables up to SharePoint and use the new relational features of SharePoint, then you need to setup the relationships in those Access tables BEFORE you send them up to SharePoint.
Every time when moved to Sharepoint list, it sets "File status" to be linked to the item.
Hum, it not clear what you mean by "item" here? Are you talking about more than one table and their PK (primary key values) and a FK (foreign key) value used to relate these two tables (or is there even more than one table involved here – I cannot tell from your description?
So sending a table up to SharePoint is in general neither an issue nor problem. Sending up tables with related data – well that is a major difference of an issue here.
As such when moving up related tables of data, this can be a challenge with SQL server or any system since often the PK auto number values will be changed on the target system during an up-load. And such a setup thus often suggests that you need a cascade update of child tables to keep the related data intact during an upload.
However, do keep in mind Access CAN upload data to SharePoint, and SharePoint WILL + CAN respect the related tables, but it will also change the PK values during an up-load. This means it is VERY VERY important to setup relationships in tables that conform to SharePoint, else you lose the logical relationship you have between tables due to auto number be re-numbered (changed) during a upload.
However, I do explain in the following video how to up-size related data from Access, and the built in tools WILL allow this type of up-sizing of data and child tables and their FK values will be automatic changed for you.
http://www.youtube.com/playlist?list=PL27E956A1537FE1C5&feature=plcp

Using Mysql Set Field Type

I want to implement a badge modification to my website, i figured that I would have one new column in my mysql database to store number variables in them, and then i can display badges based on what number is in the mysql column for each user, should i use the SET field type to accomplish this?
I would suggest you create two tables:
badges, containing the details of each badge;
userbadges, containing a pair of foreign keys - that of a user and that of a badge owned by that user.
This has the advantage over SET of enabling you to add/delete/change badges without altering your schema and also to reference badges from other tables with minimum duplication.