information-schema

MySQL not updating information_schema, unless I manually run ANALYZE TABLE `myTable`

走远了吗. 提交于 2020-08-27 21:53:29
问题 I have the need to get last id (primary key) of a table (InnoDB), and to do so I perform the following query: SELECT (SELECT `AUTO_INCREMENT` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = 'mySchema' AND `TABLE_NAME` = 'myTable') - 1; which returns the wrong AUTO_INCREMENT. The problem is the TABLES table of information_schema is not updated with the current value, unless I run the following query: ANALYZE TABLE `myTable`; Why doesn't MySQL update information_schema automatically,

mysql: access denied on information_schema

孤街醉人 提交于 2020-08-24 06:42:47
问题 When i'm create new user or grant privileges to existing, i got this error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Grant privileges ok on all tables, except information_schema, on this table i got access denied error. How i can fix? Dump all databases, drop all databases, and then restore from dump? 回答1: The MySQL documentation says: ... you can only read the contents of tables, not perform INSERT, UPDATE, or DELETE operations on them. 回答2: It is

mysql: access denied on information_schema

我与影子孤独终老i 提交于 2020-08-24 06:42:22
问题 When i'm create new user or grant privileges to existing, i got this error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Grant privileges ok on all tables, except information_schema, on this table i got access denied error. How i can fix? Dump all databases, drop all databases, and then restore from dump? 回答1: The MySQL documentation says: ... you can only read the contents of tables, not perform INSERT, UPDATE, or DELETE operations on them. 回答2: It is

Get index direction from information schema in MySQL

若如初见. 提交于 2020-06-26 05:56:51
问题 Suppose I created index with descending order CREATE INDEX `MyTable.MyIndex` USING BTREE ON `MyTable` (`DateFrom` DESC, `DateTo` DESC); I want to get information about it from information_schema . According to documentation information_schema.statistics table does the job. However I can't find any information about column order for indexes (i.e. ASC or DESC ). How can I find that information? 回答1: Where is it written in the documentation that the table statistics does the job ? Furthermore, I

NULL values for referential_constraints.unique_constraint_* columns in information schema

风流意气都作罢 提交于 2020-05-09 06:47:29
问题 In Postgres 10 I have declared the following: create table test_abc ( pk integer not null, id integer not NULL, id2 integer not null, PRIMARY KEY (pk) ); CREATE UNIQUE INDEX test_abc_ids ON test_abc(id,id2); And then a second table with a FK referencing the first: create table test_def ( id integer not null, abc_id integer, abc_id2 integer, PRIMARY KEY (id), FOREIGN KEY (abc_id,abc_id2) references test_abc(id,id2) ); Now consider the output of this query: SELECT unique_constraint_catalog,

What does the information_schema database represent?

狂风中的少年 提交于 2020-05-07 11:03:40
问题 I have one database in mysql. But when i log into phpMyAdmin , it shows another database called information_schema. Is that database always present with one database? I mean to say is there a copy of information_schema for every database present in mysql or is there one database called inforemation_schema per mysql server? If i modify this information_schema database how will that affect my current database? 回答1: You can think of information_schema as a "master database" that holds details

List all tables containing a given column name

北战南征 提交于 2020-01-22 13:36:05
问题 How do a I list all tables containing a given column name? I'm using Mysql version 4.1.13-nt-log. I know versions less than 5 dont have an information_scheme DB. 回答1: Find all tables and columns where column names are like the search term: SELECT DISTINCT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%partial_column_name%' AND TABLE_SCHEMA='YourDatabase'; 回答2: try this: mysqldump -u root -p –all-databases –single-transaction > all.sql and then do the

Update column in multiple tables

风格不统一 提交于 2020-01-15 05:36:09
问题 Let's say I have a column called partner in multiple tables within one schema: select table_name from information_schema.columns where column_name = 'partner'; How would I update all columns where value partner = 100 to partner = 101 ? 回答1: For a one-time operation, a DO statement executing dynamic SQL should serve just fine: DO $do$ DECLARE _tbl text; BEGIN FOR _tbl IN SELECT quote_ident(table_name) -- escape identifier! FROM information_schema.columns WHERE table_schema = 'public' -- your

How to alter INFORMATION_SCHEMA or add triggers or foreign keys to it?

孤街醉人 提交于 2020-01-05 08:01:34
问题 I'm trying to create some meta-data to extend mysql functionality but I can't create tables in the database INFORMATION_SCHEMA. I thought that I could just create another database and have my metadata in there but I need some foreign keys from my tables to some tables in the INFORMATION_SCHEMA DB. Nevertheless, I get errors when trying to create them. Then I thought I could create a trigger to get notified of changes but since triggers are associated to a table and I can't alter that database

sql update with dynamic column names

萝らか妹 提交于 2020-01-05 03:42:48
问题 EDIT: Database names have been modified for simplicity I'm trying to get some dynamic sql in place to update static copies of some key production tables into another database (sql2008r2) . The aim here is to allow consistent dissemination of data (from the 'static' database) for a certain period of time as our production databases are updated almost daily. I am using a CURSOR to loop through a table that contains the objects that are to be copied into the 'static' database. The prod tables