Mysql 1820 error when create procedure - mysql

I faced one issue when use mysql to create procedures.
I used "root#localhost" to create the procedure. the command executed successfully.
After that I remove procedure A and want to use "root#127.0.0.1" to create A and then faced the error: 1820 - You must SET PASSWORD before executing this statement.
Actually I have set the password for that, but still error.
And other procedure used "root#127.0.0.1" are all successfully without any error. The issue only faced on A.
As I know this error usually found on create DB. but this time... :(
Anybody can help me? Thanks very much!!!

Right from the manual:
After an account's password has been expired, all operations performed
in subsequent connections to the server using the account result in an
error until the user issues a SET PASSWORD statement to establish a
new account password:
mysql> SELECT 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('new_password');
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

Finally the issue was resolved with below statement:
++++++++++++++++++++++++++++++++++
SET PASSWORD FOR 'some_user'#'some_host' = PASSWORD('newpwd');
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Related

Master user can't connect to an existing database in Aurora MySQL - RDS [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
I have a set of databases as below
mysql> show databases;
+------------------------+
| Database |
+------------------------+
| information_schema |
| sys |
| system |
| test |
When I try to access 'test' database using the master user I'm getting below error
mysql> use information_schema;
Database changed
mysql>
mysql>
mysql> use test;
ERROR 1049 (42000): Unknown database 'test'
mysql>
Why is this error generating ?
MySQL Version 5.7
This does not strike me as a privilege issue. Otherwise, an error message should denote that as ERROR 1044 (42000): Access denied for user xx to database xxx. It's more likely there is something wrong with the data file. To demonstrate, we can create a test database.
mysql> create database test_db;
Query OK, 1 row affected (0.01 sec)
mysql> use test_db;
Database changed
-- delete the test_db database directory from OS terminal. e.g in linux shell, execute:
root#test# rm -rf /path_to_mysql_datadir/test_db
-- back to mysql cli
mysql> use test_db;
ERROR 1049 (42000): Unknown database 'test_db'
Please also note, if you directly copy a database from a remote host to your current server's mysql data directory, you are able to switch to the database, but you can not use its tables.
-- supposing we have just copied a database named db from remote server using scp
-- back to mysql cli
mysql> use db;
Database changed
mysql> show tables;
+-------------+
| Tables_in_db |
+-------------+
| p |
+-------------+
1 row in set (0.00 sec)
mysql> select * from p;
ERROR 1146 (42S02): Table 'db.p' doesn't exist
As you can see , in this case , as mysql server did not register the table of the remote copied database, querying the table returned an error.
Issue seems to be that the database was not properly created.
create database test;
Resolved the issue.

MySQL create use with permissions from anywhere fails

I'm trying to create a MySQL user with permissions from anywhere, but the command is failing:
MariaDB [(none)]> create user 'accounts'#'%' identified by 'password';
ERROR 1396 (HY000): Operation CREATE USER failed for 'accounts'#'%'
But if I change the permissions to access it from only localhost it works:
MariaDB [(none)]> CREATE USER 'accounts'#'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.01 sec)
I have a database called accounts:
MariaDB [(none)]> show databases like 'accounts';
+---------------------+
| Database (accounts) |
+---------------------+
| accounts |
+---------------------+
1 row in set (0.02 sec)
But I have to also create a user called accounts as well.
Note, I am doing this for work so I do not make decisions on who can access the DB from where.
Why does the first command fail?

MySQL Stored procedure with local variable not working in LINUX

I'm struggling with a simple stored procedure, that I've reduced to this:
CREATE PROCEDURE RemoveDuplicateModules()
BEGIN
SET #myvar=1;
End;
When I run this in the MySQL CLI I get: parameter #myvar has not been created. I'm struggling cause in windows it works fine!
mysql --version = 5.6.33
Works for me (debian, mysql 5.6.25):
mysql> delimiter //
mysql> CREATE PROCEDURE RemoveDuplicateModules()
-> BEGIN
-> SET #myvar=1;
-> End;
-> //
Query OK, 0 rows affected (0,66 sec)
mysql> call RemoveDuplicateModules();
Query OK, 0 rows affected (0,00 sec)
mysql> select #myvar ;
+--------+
| #myvar |
+--------+
| 1 |
+--------+
1 row in set (0,02 sec)
Seems that the problem here was not that the procedure I posted was failing, but since it was being executed in a larger context, a big file with a lot of code from a lot of people, a previous lack of a commit made my procedure to fail. Anyway, thanks for the help!

MySQL change database with variable value

I am setting a variable, and then I want to use the USE command to change the database. Unfortunately USE doesn't evaluate the variable.
SET #con="testDB";
Query OK, 0 rows affected (0.00 sec)
select #con;
+--------+
| #con |
+--------+
| testDB |
+--------+
1 row in set (0.00 sec)
use #con;
ERROR 1049 (42000): Unknown database '#con'
So the value of the variable is not evaluated when I try to connect. Any ideas?
I have found my own solution, so I am going to answer my own question, in case anybody is interested.
#outis you are right, it's not possible to use a variable with the command USE.
However, due to the fact that I want to create a table in a database specified at runtime, my solution would be to use dynamic SQL:
set #schema="testDB";
set #front="CREATE TABLE IF NOT EXISTS ";
set #endpart=".`TEST1` (DIM_ID INT(16)) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;";
set #stat=concat(#front,#schema,#endpart);
prepare command from #stat;
execute command;
So basically this solution builds up the statement, prepares it and executes it.
#schema parameter can even be past down to the script. This way I dynamically build the create statement.
I don't think it's possible to USE #var; in some way. But in some cases doing it the other way around might be an option.
USE testDB;
SET #schema = DATABASE();

MySQL: ERROR 1227 (42000): Access denied - Cannot CREATE USER

I'm using MySQL 5.5.16 noinstall Zip Archive on Win7.
After I started the server, the command show databases showed me a list of 2 databases: information_schema and test. The latter is empty.
Where is the table user?
I tried to create a new user through this command create user newUser; and got the following error message: ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
What should I do to create, databases, tables, and do all the operations I want to do? I don't know if the fact that I'm using MySQL 5.5.16 noinstall Zip Archive has something to do with the error message?
First thing to do is run this:
SHOW GRANTS;
You will quickly see you were assigned the anonymous user to authenticate into mysql.
Instead of logging into mysql with
mysql
login like this:
mysql -uroot
By default, root#localhost has all rights and no password.
If you cannot login as root without a password, do the following:
Step 01) Add the two options in the mysqld section of my.ini:
[mysqld]
skip-grant-tables
skip-networking
Step 02) Restart mysql
net stop mysql
<wait 10 seconds>
net start mysql
Step 03) Connect to mysql
mysql
Step 04) Create a password from root#localhost
UPDATE mysql.user SET password=password('whateverpasswordyoulike')
WHERE user='root' AND host='localhost';
exit
Step 05) Restart mysql
net stop mysql
<wait 10 seconds>
net start mysql
Step 06) Login as root with password
mysql -u root -p
You should be good from there.
CAVEAT: Please remove anonymous users !!!
For me the issue was ( for a very strange reason ) the fact that root had Host of % instead of localhost
I received the above error when trying to DROP USER;
Privileges as suggested in the answer above - I already had, so the solution wasn't suitable for me.
The DB looked like this:
mysql> drop user 'testuser'#'%';
ERROR 1227 (42000): Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
mysql> select Host,User,drop_priv from user;
+------+------------------+-----------+
| Host | User | drop_priv |
+------+------------------+-----------+
| % | mysql.infoschema | N |
| % | mysql.session | N |
| % | mysql.sys | N |
| % | root | Y |
+------+------------------+-----------+
And
mysql> SHOW GRANTS FOR 'root'#'%';
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#% |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`#`%` WITH GRANT OPTION |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
I tried many things, but eventually I changed the Host from % to localhost for security concerns, nothing else.
mysql> UPDATE user SET Host='localhost' WHERE user='root' LIMIT 1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
I don't know why, but it worked.
mysql> quit
$ mysql -u root -p
.. ENTER (NO PASSWORD) ..
mysql> drop user 'testuser'#'%';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
No idea why, but hope it will help others ...
I'm using CentOS which has SELinux and other stuff, which maybe other components are correlated with this. don't know.