I have the following users in my database:
MariaDB [racktables]> select user from mysql.user;
+----------+
| user |
+----------+
| admin |
| rackuser |
| repluser |
| root |
| root |
| root |
| |
| admin |
| rackuser |
| root |
| |
| root |
+----------+
12 rows in set (0.00 sec)
I'm trying to set up permissions but I keep getting the following error message:
MariaDB [racktables]> grant all on racktables.* to rackuser;
ERROR 1133 (42000): Can't find any matching row in the user table
MariaDB [racktables]>
The user clearly exists... I'm not sure why I'm getting this message. Unless.. this is my first crack at using mariaDB. I've imported a mysql database into mariaDB. And I'm assuming that mariaDB's users should be in the mysql.users table.
But maybe I'm wrong? I'm currently reading the mariaDB docs.. but I haven't found my answer yet.
Any tips would be appreciated.
Thanks.
I had to run the
FLUSH PRIVILEGES;
command first... and then the grants worked.
Related
I'm pretty much new to cloud services (and tbh, backend is not my area of expertise) and I'm trying to deploy my local database to google cloud so I can show my app in a portfolio.
The google cloud shell required me to log with my postgres user and password, and I think I got it right because it showed the following in the console, but there's no clue about my local databases
You are now connected to database "postgres" as user "postgres".
postgres-> [\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+-------------------+----------+------------+------------+-----------------------------------------
cloudsqladmin | cloudsqladmin | UTF8 | en_US.UTF8 | en_US.UTF8 |
postgres | cloudsqlsuperuser | UTF8 | en_US.UTF8 | en_US.UTF8 |
template0 | cloudsqladmin | UTF8 | en_US.UTF8 | en_US.UTF8 | =c/cloudsqladmin +
| | | | | cloudsqladmin=CTc/cloudsqladmin
template1 | cloudsqlsuperuser | UTF8 | en_US.UTF8 | en_US.UTF8 | =c/cloudsqlsuperuser +
| | | | | cloudsqlsuperuser=CTc/cloudsqlsuperuser
(4 rows)
postgres->
Also, I'm open to other options if anyone has a better/easier choice to upload a db (unless said option is heroku, because I couldn't make it work)
You have to migrate your on-premises PostgreSQL to GCP.
This documentation will help
https://cloud.google.com/solutions/migrating-postgresql-to-gcp
I want to get metadata of impala db in one query. Probably It will be like
SELECT columnname,tablename,schemaname from SYSTEM.INFO
Is there a way to do that? and I dont want to fetch only current tables columns for example;
SHOW COLUMN STATS db.table_name
This query is not answer of my question. I want to select all metadata in one query.
From impala-shell you have commands like:
describe table_name
describe formatted table_name
describe database_name
EXPLAIN { select_query | ctas_stmt | insert_stmt }
and the SHOW Statement that is a flexible way to get information about different types of Impala objects. You can follow this link to the Impala documentation SHOW statement.
On the other hand, information about the schema objects is held in the metastore database. This database is shared between Impala and Hive.
In particular, Impala keeps its table definitions in a traditional MySQL or PostgreSQL database known as the metastore, the same database where Hive keeps this type of data. Thus, Impala can access tables defined or loaded by Hive, as long as all columns use Impala-supported data types, file formats, and compression codecs.
If you want to query this information in one shot you would have to query to MySQL, PostgreSQL, Oracle, or etc, it's depending on your particular case.
For example, in my case Impala keeps metadata in MySQL.
use metastore;
-- Database changed
SHOW tables;
+---------------------------+
| Tables_in_metastore |
+---------------------------+
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_TXN_COMPONENTS |
| DATABASE_PARAMS |
| DBS |
.......
........
| TAB_COL_STATS |
| TBLS |
| TBL_COL_PRIVS |
| TBL_PRIVS |
| TXNS |
| TXN_COMPONENTS |
| TYPES |
| TYPE_FIELDS |
| VERSION |
+---------------------------+
54 rows in set (0.00 sec)
SELECT * FROM VERSION;
+--------+----------------+----------------------------+-------------------+
| VER_ID | SCHEMA_VERSION | VERSION_COMMENT | SCHEMA_VERSION_V2 |
+--------+----------------+----------------------------+-------------------+
| 1 | 1.1.0 | Hive release version 1.1.0 | 1.1.0-cdh5.12.0 |
+--------+----------------+----------------------------+-------------------+
1 row in set (0.00 sec)
Hope this helps.
I was creating a Audit trail table where some_user can edit a table, Autid table logs it. But some_user cannot edit the audit table
I have the following table items. which looks like this
| date | id | s_px | c_px | fee |
+------------+-----+----------+----------+-----+
| 2015-01-01 | 001 | 5355.00 | 5355.00 | 2 |
| 2015-01-01 | 002 | 13240.00 | 13240.00 | 3 |
| 2015-01-01 | 003 | 5840.00 | 5840.00 | 1 |
| 2015-01-01 | 004 | 20.55 | 20.59 | 5 |
| 2015-01-01 | 005 | 64.42 | 64.42 | 6 |
I created an audit_tb to track any changes for the table items with trigger that call a function audit_function() for any Insert, Update, Delete.
audit_function() insert any changes on items table to audit_tb.
https://wiki.postgresql.org/wiki/Audit_trigger
Everything works fine when I am a power user have all access to items and audit_tb. Problem is power_user can also modify the audit_tb.
So I created some_user which can change items, and can only select audit_tb.
The Problem is with this audit_function() cannot Insert since user some_user is limited to Select only.
ERROR: permission denied for relation audit_tb
You need to grand permission to the user
GRANT ALL PRIVILEGES ON DATABASE mydb TO admin_user;
Create audit_function() as the superuser with the option security definer. If you do that, the function will run with the privileges of the superuser (=the owner), not with the privileges of the users that triggered the function.
Does anyone know of a query that gives me details on the last time a Netezza table was accessed for any of the operations (select, insert or update) ?
Depending on your setup you may want to try the following query:
select *
from _v_qryhist
where lower(qh_sql) like '%tablename %'
There are a collection of history views in Netezza that should provide the information you require.
Netezza does not track this information in the catalog, so you will typically have to mine that from the query history database, if one is configured.
Modern Netezza query history information is typically stored in a dedicated database. Depending on permissions, you may be able to see if history collection is enabled, and which database it is using with the following command. Apologies in advance for the screen-breaking wrap to come.
SYSTEM.ADMIN(ADMIN)=> show history configuration;
CONFIG_NAME | CONFIG_DBNAME | CONFIG_DBTYPE | CONFIG_TARGETTYPE | CONFIG_LEVEL | CONFIG_HOSTNAME | CONFIG_USER | CONFIG_PASSWORD | CONFIG_LOADINTERVAL | CONFIG_LOADMINTHRESHOLD | CONFIG_LOADMAXTHRESHOLD | CONFIG_DISKFULLTHRESHOLD | CONFIG_STORAGELIMIT | CONFIG_LOADRETRY | CONFIG_ENABLEHIST | CONFIG_ENABLESYSTEM | CONFIG_NEXT | CONFIG_CURRENT | CONFIG_VERSION | CONFIG_COLLECTFILTER | CONFIG_KEYSTORE_ID | CONFIG_KEY_ID | KEYSTORE_NAME | KEY_ALIAS | CONFIG_SCHEMANAME | CONFIG_NAME_DELIMITED | CONFIG_DBNAME_DELIMITED | CONFIG_USER_DELIMITED | CONFIG_SCHEMANAME_DELIMITED
-------------+---------------+---------------+-------------------+--------------+-----------------+-------------+---------------------------------------+---------------------+-------------------------+-------------------------+--------------------------+---------------------+------------------+-------------------+---------------------+-------------+----------------+----------------+----------------------+--------------------+---------------+---------------+-----------+-------------------+-----------------------+-------------------------+-----------------------+-----------------------------
ALL_HIST_V3 | NEWHISTDB | 1 | 1 | 20 | localhost | HISTUSER | aFkqABhjApzE$flT/vZ7hU0vAflmU2MmPNQ== | 5 | 4 | 20 | 0 | 250 | 1 | f | f | f | t | 3 | 1 | 0 | 0 | | | HISTUSER | f | f | f | f
(1 row)
Also make note of the CONFIG_VERSION, as it will come into play when crafting the following query example. In my case, I happen to be using the version 3 format of the query history database.
Assuming history collection is configured, and that you have access to the history database, you can get the information you're looking for from the tables and views in that database. These are documented here. The following is an example, which reports when the given table was the target of a successful insert, update, or delete by referencing the "usage" column. Here I use one of the history table helper functions to unpack that column.
SELECT FORMAT_TABLE_ACCESS(usage),
hq.submittime
FROM "$v_hist_queries" hq
INNER JOIN "$hist_table_access_3" hta
USING (NPSID, NPSINSTANCEID, OPID, SESSIONID)
WHERE hq.dbname = 'PROD'
AND hta.schemaname = 'ADMIN'
AND hta.tablename = 'TEST_1'
AND hq.SUBMITTIME > '01-01-2015'
AND hq.SUBMITTIME <= '08-06-2015'
AND
(
instr(FORMAT_TABLE_ACCESS(usage),'ins') > 0
OR instr(FORMAT_TABLE_ACCESS(usage),'upd') > 0
OR instr(FORMAT_TABLE_ACCESS(usage),'del') > 0
)
AND status=0;
FORMAT_TABLE_ACCESS | SUBMITTIME
---------------------+----------------------------
ins | 2015-06-16 18:32:25.728042
ins | 2015-06-16 17:46:14.337105
ins | 2015-06-16 17:47:14.430995
(3 rows)
You will need to change the digit at the end of the $v_hist_table_access_3 view to match your query history version.
To migrate my database faster, I tried copying the raw files (MYD and MYI) files of a database into another machine. All the tables are working fine except two tables that were partitioned. My directory structure looks like this:
table1.frm
table1.MYI
table1.MYD
table2.frm
table2.par
table2#P#p0.MYD
table2#P#p0.MYI
table2#P#p1.MYD
table2#P#p1.MYI
table3.frm
table3.par
table3#P#p0.MYD
table3#P#p0.MYI
table3#P#p1.MYD
table3#P#p1.MYI
The following is producing an error:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.06 sec)
mysql> use test;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_test |
+---------------------------+
| table1 |
| table2 |
| table3 |
+---------------------------+
3 rows in set (0.00 sec)
mysql> explain table1;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| a | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> explain table2;
ERROR 1017 (HY000): Can't find file: 'table2' (errno: 2)
mysql> explain table3;
ERROR 1017 (HY000): Can't find file: 'table3' (errno: 2)
mysql> check TABLE table2;
+--------------------------+-------+----------+--------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------------------+-------+----------+--------------------------------------------------+
| test.table2 | check | Error | Can't find file: 'table2' (errno: 2) |
| test.table2 | check | error | Corrupt |
+--------------------------+-------+----------+--------------------------------------------------+
2 rows in set (0.00 sec)
I checked the permissions and everything looks fine. I tried repair but that didn't seem to work either. Is there anything that can be done?
The server you are porting them to might not have partioning enabled.
Try SHOW VARIABLES LIKE '%partition%'; and check the value of the variable have_partioning or have_partition_engine (depending on your version of mysql).
Further information can be found in the documentation.