Menu Close

Category: Uncategorized

MySQL force user change password

Since version 5.6.6 MySQL has introduced the capability to force an user to change their password. You can archive that by issue ALTER USER PASSWORD EXPIRE statement. ALTER USER ‘marcelo’@’localhost’ PASSWORD EXPIRE; Next time marcelo tries to login from localhost it will block all statements rather then SET PASSWORD; mysql> \s ERROR 1820 (HY000): You must SET PASSWORD before executing this statement To remove this block, just issue an : SET PASSWORD = PASSWORD(‘pwd’); #Or use the hash received from SELECT PASSWORD(‘pwd’); SET PASSWORD = ‘*975B2CD4FF9AE554FE8AD33168FBFC326D2021DD’; But be careful, if you expire the password for an account, you won’t be able to login with any client version before 5.6.10(GA): ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords. . . .

Liked? Help and Share!

How to rename table in MYSQL

To rename a table in MySQL you just need to run a command named RENAME TABLE, the syntax is very easy to use, RENAME TABLE tb1 TO tb2; The RENAME TABLE command will rename the table atomically, which means your table will be locked during the command. You can also rename more than one table in one command: RENAME TABLE tb1 TO tb2, tb3 TO tb4; To rename the table you will need ALTER and DROP privileges on the old table and CREATE and INSERT on the new one. You just need to be careful if you use triggers, on the bellow example, after a INSERT on table Cities, I count +1 to NOfCities on the iserted Countries, what happens if I rename the table Contries? mysql> SHOW TRIGGERS\G *************************** . . .

Liked? Help and Share!


MySQL IN??? MySQL OR??? MySQL AND??? When I use one and when I use other? we will use the city table to this tutorial: +————-+———-+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra | +————-+———-+——+—–+———+—————-+ | ID | int(11) | NO | PRI | NULL | auto_increment | | Name | char(35) | NO | | | | | CountryCode | char(3) | NO | MUL | | | | District | char(20) | NO | | | | | Population | int(11) | NO | | 0 | | +————-+———-+——+—–+———+—————-+ Let’s see a simple rule to clarify this: AND – we use AND to add a new condition which will need to be true: SELECT * FROM City WHERE CountryCode = 'BRA' AND Population > . . .

Liked? Help and Share!

How to rename a database in MySQL?

Today we will talk how do you can easily rename a database in MySQL. At the MySQL version 5.1.7 was added a command to do this job named RENAME DATABASE RENAME {DATABASE | SCHEMA} db_name TO new_db_name; But it was removed on the MySQL version 5.1.23 because maybe it would result in data lost’s. Then, let’s see some ways in which we can do this: 1. Using the RENAME TABLE command As long as two databases are on the same file system, you can use RENAME TABLE to move a table from one database to another: RENAME TABLE current_db.tbl_name TO other_db.tbl_name; RENAME TABLE Syntax na Documentacao do MySQL mysql> show tables; +———————+ | Tables_in_oldSchema | +———————+ | tb1 | | tb10 | | tb2 | | tb3 | | tb4 . . .

Liked? Help and Share!