Drop user without a name from sql database - sql

Executing the following command
MariaDB [(none)]> select distinct user from mysql.user;
results in
+-------------+
| User |
+-------------+
| app_user |
| |
| test_u |
| mariadb.sys |
| root |
+-------------+
5 rows in set (0.001 sec)
So I have probably created a user with no name, correct? Perhaps by using a wrong syntax in the past. Question is how to drop the user? Something like the following doesn't seem to work:
MariaDB [(none)]> drop user ' ';
ERROR 1396 (HY000): Operation DROP USER failed for ' '#'%'

drop is used to remove tables https://dev.mysql.com/doc/refman/8.0/en/drop-table.html, DROP TABLE User
Try DELETE FROM User WHERE User.user = ' '

After some trial and error I stumbled upon mysql.user does not exist. During the execution of mysql_secure_installation the terminal states
By default, a MariaDB installation has an anonymous user, allowing
anyone to log into MariaDB without having to have a user account
created for them. This is intended only for testing, and to make the
installation go a bit smoother. You should remove them before moving
into a production environment.
Remove anonymous users? [Y/n] Y
... Success!
So this ' ' user is equal to the anonymous user described here. Running select distinct user from mysql.user; after the removal of anonymous users.
Results in
+-------------+
| User |
+-------------+
| app_user |
| test_u |
| mariadb.sys |
| root |
+-------------+
So probably this ' ' user was already there.

Related

Impala ACID table select ERROR: Operation not supported on transactional (ACID) table:

I'm using impala 3.4 directly with hive 3.1.
The problem is that if you create a general table in the hive and then select it in impala, an error occurs.
The error message is as follows:
Query: show tables
+----------+
| name |
+----------+
| customer |
| lineitem |
| nation |
| orders |
| part |
| partsupp |
| region |
| supplier |
| t |
+----------+
Fetched 9 row(s) in 0.02s
[host.cluster.com] default> select * from customer;
Query: select * from customer
Query submitted at: 2020-11-20 09:56:12 (Coordinator: http://host.cluster.com:25000)
ERROR: AnalysisException: Operation not supported on transactional (ACID) table: default.customer
In the hive, the acid table and the orc table are only concerned with whether to delete or update, but I knew that selection is common.
In fact, the select statement is normally executed through hive jdbc. Only impala would like to help you understand why this error occurs.
I solved this problem. It was confirmed that the table created through Hive in impala operates normally.
There are two possible causes:
Connect impala built with Hive2 to Hive 3 databases.
When creating a Hive Table that I did not recognize, set the default flag related to ACID.
This version can't read ACID table wich are created by Hive. Hive creates ACID table by default.

Apache sentry hive grant insert privileges but it did not work

insert into limifang_oracle_store002(id,name) values(1,'lisi');
exception:
Error: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.InvalidTableException: Table not found limifang_oracle_store002 (state=42000,code=40000)
0: jdbc:hive2://192.168.2.16:2181,192.168.2.1> insert into liminfang_oracle_store002(id,name) values(1,'lisi');
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Error: org.apache.hive.service.cli.HiveSQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. Permission denied: user=kaif1, access=EXECUTE, inode="/tmp/hadoop-yarn/staging/kaif1/.staging":root:supergroup:drwx------
Permission information is as follows:
show grant role kaif1;
|database| table | partition | column | principal_name | principal_type | privilege | grant_option | grant_time | grantor |
| ziy_db_109 | liminfang_oracle_store002 | kaif1 | ROLE | DELETE | false | 1022296989000
| ziy_db_109 |liminfang_oracle_store002 | kaif1 | ROLE | INSERT | false | 1022295356000 |
Check the Hadoop cluster HDFS in those groups, if there are hadoop, hdfs, supergroup and other groups.
first establish the corresponding user test and supergroup groups (Hadoop or HDFS group) in the Linux system.
2 add test users to the supergroup group (or Hadoop, HDFS group).
3 Connect hive with hive user (administrator) beeline, create role: test_role, execute command: create role test_role;
4 grant permission to test_role and execute the command: grant all on testdb. testtable to role test_role; (there must be a library testdb, table testtable in his)
5 assign the test_role role to the test user to execute the command :grant test_role to group test;
verify that use test user beeline to connect hive: use testdb; show tables; check if it is wrong.

How do I resolve a MariaDB possibly corrupted table error when it doesn't look corrupted

I had 2 theories. 1. that it was a permissions error 2. that the table was corrupt. I seem to addressed both without result. What could cause this ERROR 1728 message?
Running it as mysql user does not work
MariaDB [mysql]> DROP FUNCTION IF EXISTS civicrm_strip_non_numeric;
ERROR 1728 (HY000): Cannot load from mysql.proc. The table is probably corrupted
It does not say that it is corrupt.
MariaDB [mysql]> repair table proc;
+------------+--------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+------------+--------+----------+----------+
| mysql.proc | repair | status | OK |
+------------+--------+----------+----------+
This fixes it
mysql_upgrade -u root -pxxx
wasn't aware that I upgraded as this is a new installation.
same for mariadb as mysql

Triggering mysql delete in another table?

I have 3 tables in my database:
| systems |
|-------------|
| system_id |
|-------------|
| systems_maintenances |
|-------------------------|
| systems_maintenances_id|
| system_id |
| maintenance_id |
|-------------------------|
| maintenances |
|-------------------------|
| maintenance_id |
|-------------------------|
I'd like that when I delete a system, the maintenance being deleted too.
For the moment it only deletes in the systems_maintenances table.
I think a trigger is the best (and only?) way to do that.
I created this one:
CREATE TRIGGER `deleteMaintenance` BEFORE DELETE ON `systems`
FOR EACH ROW BEGIN
DELETE FROM maintenances
WHERE maintenance_id = systems_maintenances.maintenance_id;
END
The problem is I get the error:
DELETE FROM SNMProject.systems WHERE systems.system_id =16
MySQL a répondu:
#1054 - Unknown column 'systems_maintenances.maintenance_id' in 'where clause
How to solve my problem?
I don't know if it can help but I have this too for the systems_maintenances table:
(source: xooimage.com)
In a trigger, you don't refer to the table name of the table being affected. Instead, you refer to a proxie for it. That proxie depends on the database. In MySQL, it is new and old.
I suspect that you want something like this:
CREATE TRIGGER `deleteMaintenance` BEFORE DELETE ON `systems` FOR EACH ROW BEGIN
DELETE FROM maintenances m
WHERE maintenance_id IN (SELECT maintenance_id
FROM systems_maintenances sm
WHERE systems_maintenances.system_id = old.system_id
)
END;
There are other ways to express this logic, but this gives a good idea of the structure.
You can do essentially the same thing using cascading deletes, if you prefer. That way, you don't have to write triggers and can put the logic in the create table statement.

MySQL data version control

Is there any way to setup MySQL to every time a row is changed, then a row to another table/database is created with what the data was originally? (with time stamping)
If so how would I go about doing it?
E.g.
UPDATE `live_db`.`people`
SET `live_db`.`people`.`name` = 'bob'
WHERE `id` = 1;
Causes this to happen before the update:
INSERT INTO `changes_db`.`people`
SELECT *
FROM `live_db`.`people`
WHERE `live_db`.`people`.`id` = 1;
And if you did it again it would result in something like this:
`live_db`.`people`
+----+-------+---------------------+
| id | name | created |
+----+-------+---------------------+
| 1 | jones | 10:32:20 12/06/2010 |
+----+-------+---------------------+
`changes_db`.`people`
+----+-------+---------------------+
| id | name | updated |
+----+-------+---------------------+
| 1 | billy | 12:11:25 13/06/2010 |
| 1 | bob | 03:01:54 14/06/2010 |
+----+-------+---------------------+
The live DB needs to have a created time stamp on the rows, and the changes DB needs to have a time stamp of when the live DB row was updated.
The changes DB will also have no primary keys and foreign key constraints.
I'm using InnoDB and MySQL 5.1.49 but can upgrade if required.
Use a Trigger
MySQL support for triggers started with MySQL version 5.0.2.
You can create a trigger:
DELIMITER \\
CREATE TRIGGER logtrigger BEFORE UPDATE ON live_db.people
FOR EACH ROW BEGIN
INSERT INTO changes_db.people(id,name,updated) VALUES(OLD.id,OLD.name,now());
END;
\\
This is how I ended up doing it
DELIMITER |
# Create the log table
CREATE TABLE IF NOT EXISTS `DB_LOG`.`TABLE`
LIKE `DB`.`TABLE`|
# Remove any auto increment
ALTER TABLE `DB_LOG`.`TABLE` CHANGE `DB_LOG`.`TABLE`.`PK` `DB_LOG`.`TABLE`.`PK` INT UNSIGNED NOT NULL|
# Drop the primary keys
ALTER TABLE `DB_LOG`.`TABLE` DROP PRIMARY KEY|
#Create the trigger
DROP TRIGGER IF EXISTS `DB`.`update_TABLE`|
CREATE TRIGGER `DB`.`update_TABLE` BEFORE UPDATE ON `DB`.`TABLE` FOR EACH ROW
BEGIN
INSERT INTO `DB_LOG`.`TABLE`
SELECT `DB`.`TABLE`.*
FROM `DB`.`TABLE`
WHERE `DB`.`TABLE`.`PK` = NEW.`PK`;
END|
DELIMITER ;
Sorry to comment on an old post, but I was looking to solve this exact problem! Thought I would share this information.
This outlines a solution perfectly:
http://www.hirmet.com/mysql-versioning-records-of-tables-using-triggers