Bright DBA

ORACLE DBA – Tips and Techniques

Skip to content
  • Home
  • DBA Monitor
    • DBA Sheet v7.0
    • OS-DB-Commands
    • Database-Scripts
    • Generate INSERT statements from the SELECT query
    • Generate INSERT statements to a flat file using a PL/SQL query
  • Oracle
    • DB-Install
      • Install Oracle AI Database 26ai
      • Install 19c GUI
      • Install 19c in silent mode
      • Install 18c
      • Install 12.2 Database Binaries in silent mode
      • Install Oracle Software in silent mode 11gR2
      • Install 10g
      • Deinstall Oracle 11gR2 Database binaries
      • Deinstall Oracle 18c Database Binaries
      • Oracle 19c Deinstall
      • Uninstall Oracle Client on Windows
    • DB-Upgrade
      • Upgrade DB using DBUA from 11.2.0.4 to 12.2.0.1
      • Upgrade DB Manually 11.2.0.4 to 12.2.0.1
      • Upgrade Oracle Database from 12.2.0.1 to 19c using DBUA
      • Upgrade Oracle Database Manually from 12.2.0.1 to 19c
      • Rolling Upgrade With an Existing Physical Standby Database
      • Upgrade TIMEZONE Version
      • Upgrade Database to 12.2 with Physical Standby
    • Patching
      • Patch Terminology
      • Apply Patch RU on Database 19c
      • 18c DB Patching
      • 18c DB Patching – Youtube
      • Apply RU on DATABASE 12.2
      • ROLLBACK RU from DATABASE 12.2
      • Apply DB PSU on Standby
    • DB-Admin
      • Oracle Container Database (CDB)
        • CREATE NEW PDB BY CLONING AN EXISTING PDB
        • CREATE PDB USING DBCA
        • CREATE PDB USING SEED
        • DROP PDB MANUALLY
        • STARTUP/SHUTDOWN CDB AND PDB
        • Convert Non-CDB to PDB with DBMS_PDB
        • SCHEMA REFRESH FROM 11G TO 12C PDB
      • Non-CDB
        • Store DB credentials in Oracle Wallet
        • Create database -DBCA silent mode
        • Drop Database
        • Delete database -DBCA silent mode
        • Create DB 19C – DBCA-GUI
        • Create DB 19C – DBCA-SILENT
        • CREATE NON-CDB ON ORACLE 12C IN SILENT MODE
        • Configure OEM Express 12c
        • Create Non-CDB on Oracle 12c using DBCA (GUI)
        • How to Change MAX_STRING_SIZE on Physical Standby Environment
        • How to change SQL  prompt to show connected user and database name
        • Enable Archivelog
        • Change Archive Dest
        • How to Recover Loss of DATA – (Without a Backup!)
        • Configure OEM DBConsole manually
        • Proxy User
        • Database Link
        • DBMS_SCHEDULER
        • Enable/Disable JOBS during Maintenance
        • ORA-00054
        • Blocking Sessions
        • Create Service using DBMS_SERVICE
        • Error TNS-12543
      • Under Edit
    • BACKUP
      • How to Recover Loss of DATA – (Without a Backup!)
      • BACKUP ORACLE HOME AND INVENTORY
      • SCHEMA REFRESH FROM 11G TO 12C PDB
      • RMAN-CATALOG
      • RMAN Database Restore RAC – RAC
      • RMAN Database Restore ASM – ASM
      • RMAN Database Restore from ASM to File System
      • RMAN ACTIVE DUPLICATION ASM TO ASM
      • Backup Based RMAN Duplicate Database
  • ExaDB
    • Oracle Exadata – Overview
    • Exadata DB Server (Compute Node)
    • Exadata Storage Server (Cell Node)
    • ExaData infi Network
    • Exadata Part Replacement Runbook
    • CellCLI Commands
  • PT
    • Tuning Stage 1
      • Statistics
      • Oracle Histograms
      • Export/Import schema statistics
      • CONTROL MANAGEMENT PACK ACCESS
      • Generate Explain Plan
      • SQL Query is really hanged or not
    • Tuning Stage 2
      • STATSPACK
      • ASH
      • AWR
      • Colored SQL_ID
      • SYSAUX Tablespace
    • Tuning Stage 3
      • Troubleshooting Long Running Queries
      • SQL Tuning Advisor
      • SQLT
        • How to Install SQLT
        • How to Run SQLT
        • How to Create Custom SQL Profile
        • Uninstall SQLT
      • Tracing
      • TRCA – Trace Analyzer
    • FF Analysis (Advanced Troubleshooting)
      • Fire-Fighting Analysis (Ongoing / Live Issues)
        • Explain Plan Analysis
        • Top SQL Analysis
        • 10046 Trace Analysis
        • 10053 Trace Analysis
      • Forensic Analysis (RCA – Completed Issues)
  • HA
    • CONFIGURATION
      • Active Dataguard on Non-ASM
      • Active Dataguard on ASM
      • Convert Physical Standby Database to Snapshot Standby Database
      • Convert Snapshot Standby database to Physical Standby database
      • Configure Cascading Standby Database
      • DG Broker Configuration
      • DG Broker Error – ORA-16714
      • Disable DG Broker
      • 12.2 Active Dataguard in CDB on Non-ASM
      • Create Physical Standby using RMAN Backup Without Duplicate Command
      • Create Physical Standby using RMAN Backup with Duplicate Command
      • 12c DG Broker Configuration
    • SWITCHOVER
      • Switchover Manual No-Broker
      • Switchover with Broker
    • FAILOVER
      • Failover with Broker(No Flashback)
      • Failover with No Broker (No Flashback)
      • Failover with Broker using Flashback
      • Failover with No Broker using Flashback
    • Enable Real-Time Apply
    • Refresh Standby Database using RMAN Incremental SCN Backup
    • Resetlogs on Primary where Standby in place
    • Drop SRL
  • RAC
    • Create users, groups and Paths for Oracle RAC
    • Configure ASMLib for Oracle ASM
    • Configure UDEV Rules for Oracle ASM
    • ASM
      • Move ASM Spfile to diff. DiskGroup
      • ASM Commands
      • Instantiating disk: failed
      • CSSD won’t start automatically
    • RAC Install
      • RAC Install 11.2.0.3
      • Upgrade GI to 11.2.0.4
      • Downgrade GI to 11.2.0.3
      • root.sh failed with ORA-29783 on RAC
      • Delete Node
      • Add Node
      • Delete Node without remove software
      • Add Node Back which was DELETED without remove software
    • RAC Admin
      • How to take OCR backup on 11.2.0.4
      • Cluster Name
      • Move/Relocate OCR
      • Restore loss of all VOTE disk
      • Cluster Startup issues
      • Add SCAN
    • RAC Tools
      • CLUVFY
      • OSWatcher
    • RAC Standby 12.2
    • Create ACFS File System on RAC
  • GG
    • GoldenGate Installation
    • Unidirectional DML Replication
    • Zero Downtime Migration
    • DDL Replication
    • GoldenGate 12C Installation
    • Integrated Capture
    • Oracle GoldenGate Heterogeneous Replication
    • Credential Store
    • ADD NEW TABLE TO AN EXISTING GOLDENGATE CONFIGURATION
    • Install Oracle GoldenGate 19C for Database 12C
    • Install Oracle GoldenGate 19C for Database 19C
  • OEM
    • Install OEM 13.2
    • Install OEM 13.3
    • Add Targets Manually on EM Cloud Control 13c
    • Upgrade OMSPatcher
    • Apply Patch on OMS 13.1
    • Apply Patch on Agent 13.1
  • MS-SQL
    • Installation & Basics
      • SQL Server Basics
      • Install Microsoft SQL Server Express 2014
      • Install Only SQL Server Management Studio
      • Create Database using GUI
      • Enable TCP/IP Connection
      • Allow Remote Connection
    • Security & User Management
      • Authentication Method
      • Create SQL Server Authenticated Login in SQL Server
      • Create Windows Group Authentication Login in SQL Server
      • Create Windows Authentication Login
      • Create SQL Server Authenticated Login in SQL Server
      • Create a new domain user account in Windows
    • Backup & Recovery
      • SQL Server – Recovery Models
      • Database Backup-FULL-DIFFERENTIAL-TLOG
      • Restore Database without Tail Backup
    • High Availability
      • Log Shipping (SQL Server 2022)
      • Windows Server 2022 Failover Cluster
      • Setup 4 Node Always On Availability Group
      • Who is NT AUTHORITY\SYSTEM?
      • Add Database to Existing AG using Backup and Restore
      • Manual Failover (Planned)
      • Automatic Failover (Unplanned)
  • MySQL
    • Install MySQL 8 on Linux 7 Using RPM Packages
    • Create MySQL Database
    • Create New User Account in MySQL
    • Grant Privileges in MySQL
    • Create Roles in MySQL
    • How To Backup MySQL Database Using mysqldump
    • How to Restore Database from Single MySQL Database Backup
    • How to Restore A Single Database From A Backup File Which Contains Multiple Databases
    • How To Restore Single Table From Full Database Backup in MySQL
    • How To Configure MySQL Master-Slave Replication?
  • PostgreSQL
    • Installation & Basics
      • Install PostgreSQL 15 using yum Repository on Linux
      • Install PostgreSQL Using Source Code
      • How to START/STOP PostgreSQL 13 on Linux
      • Create Database in PostgreSQL
    • Security & User Management
      • PostgreSQL User Management
      • pg_hba conf
    • Storage & Architecture
      • Change Data Directory
      • WAL Files
      • Change pg_wal path
      • PostgreSQL Tablespace
    • Backup & Recovery
      • Enable Archive Mode
      • Disable ARCHIVELOG
      • Logical – pg_dump and pg_restore (Backup & Restore)
      • Logical – pg_dumpall (Backup & Restore)
      • Physical – pg_basebackup (Backup and Restore)
      • Backup & Restore to Another Host (No Archive Mode)
      • Backup & Restore on Same Host
      • Restore PostgreSQL to New Host using pg_basebackup + WAL Archives
      • PostgreSQL PITR – Point in Time Recovery
    • High Availability
      • Streaming Replication
      • Manual Failover – Streaming Replication
      • Synchronous Replication
      • PostgreSQL HA Setup with REPMGR + Automatic Failover
  • DB2
    • Install DB2 V10.5 using GUI
    • DB2 STOP and START
    • DB2 Troubleshooting Guide
  • DevOps
    • How to Install Jenkins on Linux

Create New User Account in MySQL

Create New User Account in MySQL

Table of Contents
___________________________________________________________________________________________________

1. Login to MySQL
2. How to List all existing users?
3. How to Create new user?
4. How to Connect to New User Account using Password?
5. How To Change the Password for Your Own User Account?
6. How To Change the Password of Another User Account?
7. How to Lock user account?
8. How to Unlock user account?
9. How To Rename an Existing User Account Name?
10. How to Drop user?
___________________________________________________________________________________________________


1. Login to MySQL

[root@rac1 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


2. How to List all existing users?

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql> select database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> select database ();
+-------------+
| database () |
+-------------+
| mysql       |
+-------------+
1 row in set (0.00 sec)

mysql>

mysql> show tables;
+------------------------------------------------------+
| Tables_in_mysql                                      |
+------------------------------------------------------+
| columns_priv                                         |
| component                                            |
| db                                                   |
| default_roles                                        |
| engine_cost                                          |
| func                                                 |
| general_log                                          |
| global_grants                                        |
| gtid_executed                                        |
| help_category                                        |
| help_keyword                                         |
| help_relation                                        |
| help_topic                                           |
| innodb_index_stats                                   |
| innodb_table_stats                                   |
| password_history                                     |
| plugin                                               |
| procs_priv                                           |
| proxies_priv                                         |
| replication_asynchronous_connection_failover         |
| replication_asynchronous_connection_failover_managed |
| role_edges                                           |
| server_cost                                          |
| servers                                              |
| slave_master_info                                    |
| slave_relay_log_info                                 |
| slave_worker_info                                    |
| slow_log                                             |
| tables_priv                                          |
| time_zone                                            |
| time_zone_leap_second                                |
| time_zone_name                                       |
| time_zone_transition                                 |
| time_zone_transition_type                            |
| user                                                 |
+------------------------------------------------------+
35 rows in set (0.00 sec)

mysql>

mysql> desc user;
+--------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field                    | Type                              | Null | Key | Default               | Extra |
+--------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host                     | char(255)                         | NO   | PRI |                       |       |
| User                     | char(32)                          | NO   | PRI |                       |       |
| Select_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Insert_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Update_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Delete_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Create_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Drop_priv                | enum('N','Y')                     | NO   |     | N                     |       |
| Reload_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Shutdown_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Process_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| File_priv                | enum('N','Y')                     | NO   |     | N                     |       |
| Grant_priv               | enum('N','Y')                     | NO   |     | N                     |       |
| References_priv          | enum('N','Y')                     | NO   |     | N                     |       |
| Index_priv               | enum('N','Y')                     | NO   |     | N                     |       |
| Alter_priv               | enum('N','Y')                     | NO   |     | N                     |       |
| Show_db_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Super_priv               | enum('N','Y')                     | NO   |     | N                     |       |
| Create_tmp_table_priv    | enum('N','Y')                     | NO   |     | N                     |       |
| Lock_tables_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Execute_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Repl_slave_priv          | enum('N','Y')                     | NO   |     | N                     |       |
| Repl_client_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Create_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Show_view_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Create_routine_priv      | enum('N','Y')                     | NO   |     | N                     |       |
| Alter_routine_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Create_user_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Event_priv               | enum('N','Y')                     | NO   |     | N                     |       |
| Trigger_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Create_tablespace_priv   | enum('N','Y')                     | NO   |     | N                     |       |
| ssl_type                 | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |
| ssl_cipher               | blob                              | NO   |     | NULL                  |       |
| x509_issuer              | blob                              | NO   |     | NULL                  |       |
| x509_subject             | blob                              | NO   |     | NULL                  |       |
| max_questions            | int unsigned                      | NO   |     | 0                     |       |
| max_updates              | int unsigned                      | NO   |     | 0                     |       |
| max_connections          | int unsigned                      | NO   |     | 0                     |       |
| max_user_connections     | int unsigned                      | NO   |     | 0                     |       |
| plugin                   | char(64)                          | NO   |     | caching_sha2_password |       |
| authentication_string    | text                              | YES  |     | NULL                  |       |
| password_expired         | enum('N','Y')                     | NO   |     | N                     |       |
| password_last_changed    | timestamp                         | YES  |     | NULL                  |       |
| password_lifetime        | smallint unsigned                 | YES  |     | NULL                  |       |
| account_locked           | enum('N','Y')                     | NO   |     | N                     |       |
| Create_role_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Drop_role_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Password_reuse_history   | smallint unsigned                 | YES  |     | NULL                  |       |
| Password_reuse_time      | smallint unsigned                 | YES  |     | NULL                  |       |
| Password_require_current | enum('N','Y')                     | YES  |     | NULL                  |       |
| User_attributes          | json                              | YES  |     | NULL                  |       |
+--------------------------+-----------------------------------+------+-----+-----------------------+-------+
51 rows in set (0.00 sec)

mysql> select host,User from user;
+-----------+------------------+
| host      | User             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> 

---- OR -----------

mysql> use dell;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql>

---- OR ------------

select * from INFORMATION_SCHEMA.USER_ATTRIBUTES;


3. How to Create new user?

mysql> select database();
+------------+
| database() |
+------------+
| dell       |
+------------+
1 row in set (0.00 sec)

mysql> 

-- CREATE NEW USER, raj=username, localhost=from where user raj can connect to mysql db
mysql> create user 'raj'@'localhost' identified by 'Raj_123%';
Query OK, 0 rows affected (0.01 sec)

mysql>

-- srinu@% -- srinu user can connect from any host
mysql> create user 'srinu'@'%' identified by 'Srinu_123%';
Query OK, 0 rows affected (0.01 sec)

mysql>


-- sugi@192.168.2.% -- sugi user can connect from any host using 192.168.2.0 subnet.
mysql> create user 'sugi'@'192.168.2.%' identified by 'Sugi_123%';
Query OK, 0 rows affected (0.01 sec)

mysql>

-- teja@192.168.2.102 -- teja user allowed only from host ip 192.168.2.102
mysql> create user 'teja'@'192.168.2.102' identified by 'Teja_123%';
Query OK, 0 rows affected (0.01 sec)

mysql>


-- create user with comment
mysql> create user sunil@localhost identified by 'Sunil_123%' COMMENT 'Sunil - Local User';
Query OK, 0 rows affected (0.01 sec)

mysql>

mysql> select * from INFORMATION_SCHEMA.USER_ATTRIBUTES where user = 'sunil' and host = 'localhost';
+-------+-----------+-----------------------------------+
| USER  | HOST      | ATTRIBUTE                         |
+-------+-----------+-----------------------------------+
| sunil | localhost | {"comment": "Sunil - Local User"} |
+-------+-----------+-----------------------------------+
1 row in set (0.00 sec)

mysql>


-- create user with attribute
mysql> create user 'mike'@'localhost' identified by 'Mike_123%' ATTRIBUTE '{"Name":"Mike","Role":"DBA"}';
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> select * from INFORMATION_SCHEMA.USER_ATTRIBUTES where user = 'mike' and host = 'localhost';
+------+-----------+---------------------------------+
| USER | HOST      | ATTRIBUTE                       |
+------+-----------+---------------------------------+
| mike | localhost | {"Name": "Mike", "Role": "DBA"} |
+------+-----------+---------------------------------+
1 row in set (0.00 sec)

mysql>

-- creating a user that can connect from multiple hosts

mysql> create user 'scott'@'localhost' identified by 'Scott_1%';
Query OK, 0 rows affected (0.01 sec)

mysql> create user 'scott'@'192.168.%.%' identified by 'Scott_12%';
Query OK, 0 rows affected (0.01 sec)

mysql> create user 'scott'@'192.168.2.%' identified by 'Scott_123%';
Query OK, 0 rows affected (0.01 sec)

mysql> create user 'scott'@'192.168.2.102' identified by 'Scott_1234%';
Query OK, 0 rows affected (0.00 sec)

mysql>

mysql> select user,host from INFORMATION_SCHEMA.USER_ATTRIBUTES where user = 'scott';
+-------+---------------+
| USER  | HOST          |
+-------+---------------+
| scott | 192.168.%.%   |
| scott | 192.168.2.%   |
| scott | 192.168.2.102 |
| scott | localhost     |
+-------+---------------+
4 rows in set (0.00 sec)

mysql>


mysql> select host,user from mysql.user order by user;
+---------------+------------------+
| host          | user             |
+---------------+------------------+
| localhost     | mike             |
| localhost     | mysql.infoschema |
| localhost     | mysql.session    |
| localhost     | mysql.sys        |
| localhost     | raj              |
| localhost     | root             |
| 192.168.%.%   | scott            |
| 192.168.2.%   | scott            |
| 192.168.2.102 | scott            |
| localhost     | scott            |
| %             | srinu            |
| 192.168.2.%   | sugi             |
| localhost     | sunil            |
| 192.168.2.102 | teja             |
+---------------+------------------+
14 rows in set (0.00 sec)  mysql>
mysql>

-- create user with password expire 
mysql> create user 'hr'@'localhost' identified by 'Hr_1234%' password expire;
Query OK, 0 rows affected (0.01 sec)

mysql>

[root@rac1 ~]# mysql -u hr -pHr_1234%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.23

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>

mysql> SET PASSWORD = 'Hr_123%_';
Query OK, 0 rows affected (0.01 sec)

mysql>

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql>



4. How to Connect to New User Account using Password?

[root@rac1 ~]# mysql -u scott -pScott_1%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> SELECT USER();
+-----------------+
| USER()          |
+-----------------+
| scott@localhost |
+-----------------+
1 row in set (0.00 sec)

mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql>


5. How To Change the Password for Your Own User Account?

[root@rac1 ~]# mysql -u raj -pRaj_123%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT USER();
+---------------+
| USER()        |
+---------------+
| raj@localhost |
+---------------+
1 row in set (0.00 sec)

mysql> SET PASSWORD = 'Raj_1234%';
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> exit
Bye
[root@rac1 ~]# mysql -u raj -pRaj_1234%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT USER();
+---------------+
| USER()        |
+---------------+
| raj@localhost |
+---------------+
1 row in set (0.00 sec)

mysql> 
---------------- OR -----------------

[root@rac1 ~]# mysql -u raj -pRaj_1234%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER USER() IDENTIFIED BY 'Raj_12345%';
Query OK, 0 rows affected (0.01 sec)

mysql>


6. How To Change the Password of Another User Account?

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql> SET PASSWORD FOR 'raj'@'localhost' = 'Raj_12345%';
Query OK, 0 rows affected (0.01 sec)

mysql>

[root@rac1 ~]# mysql -u raj -h localhost -pRaj_12345%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user();
+---------------+
| user()        |
+---------------+
| raj@localhost |
+---------------+
1 row in set (0.00 sec)

mysql>

-------- OR --------

mysql> use mysql;
Database changed
mysql> ALTER USER 'raj'@'localhost' IDENTIFIED BY 'Amudala%12';
Query OK, 0 rows affected (0.01 sec)

mysql>

[root@rac1 ~]# mysql -u raj -h localhost -pAmudala%12
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user();
+---------------+
| user()        |
+---------------+
| raj@localhost |
+---------------+
1 row in set (0.00 sec)

mysql>


7. How to Lock user account?

[root@rac1 mysql]# mysql -u root -h localhost -pMysql@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'raj'@'localhost' ACCOUNT LOCK;
Query OK, 0 rows affected (0.01 sec)

mysql> 

[root@rac1 ~]# mysql -u raj -h localhost -pAmudala%12
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 3118 (HY000): Access denied for user 'raj'@'localhost'. Account is locked.
[root@rac1 ~]#  
mysql> select database ();
+-------------+
| database () |
+-------------+
| mysql       |
+-------------+
1 row in set (0.00 sec)

mysql>
mysql> select user,host,account_locked from user where user='raj' and host='localhost';
+------+-----------+----------------+
| user | host      | account_locked |
+------+-----------+----------------+
| raj  | localhost | Y              |
+------+-----------+----------------+
1 row in set (0.00 sec)

mysql> 


8. How to Unlock user account?

mysql> select database ();
+-------------+
| database () |
+-------------+
| mysql       |
+-------------+
1 row in set (0.00 sec)

mysql>
mysql> select user,host,account_locked from user where user='raj' and host='localhost';
+------+-----------+----------------+
| user | host      | account_locked |
+------+-----------+----------------+
| raj  | localhost | Y              |
+------+-----------+----------------+
1 row in set (0.00 sec)

mysql> 

mysql> ALTER USER 'raj'@'localhost' ACCOUNT UNLOCK;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,account_locked from user where user='raj' and host='localhost';
+------+-----------+----------------+
| user | host      | account_locked |
+------+-----------+----------------+
| raj  | localhost | N              |
+------+-----------+----------------+
1 row in set (0.01 sec)

mysql>


9. How To Rename an Existing User Account Name?

mysql> select user,host,account_locked from mysql.user where user='hr';
+------+-----------+----------------+
| user | host      | account_locked |
+------+-----------+----------------+
| hr   | localhost | N              |
+------+-----------+----------------+
1 row in set (0.00 sec)

mysql> RENAME USER 'hr'@'localhost' TO 'hr1'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,account_locked from mysql.user where user='hr';
Empty set (0.00 sec)

mysql> select user,host,account_locked from mysql.user where user='hr1';
+------+-----------+----------------+
| user | host      | account_locked |
+------+-----------+----------------+
| hr1  | localhost | N              |
+------+-----------+----------------+
1 row in set (0.00 sec)

mysql> 


10. How to Drop user?

mysql> select user,host,account_locked from mysql.user where user='hr1';
+------+-----------+----------------+
| user | host      | account_locked |
+------+-----------+----------------+
| hr1  | localhost | N              |
+------+-----------+----------------+
1 row in set (0.00 sec)

mysql>

mysql> DROP USER 'hr1'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,account_locked from mysql.user where user='hr1';
Empty set (0.00 sec) <---- User hr1 not found.

mysql>

Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.

Thank you,
Rajasekhar Amudala
Email: br8dba@gmail.com
WhatsApp : +
Linkedin: https://www.linkedin.com/in/rajasekhar-amudala/

Reference:

https://dev.mysql.com/doc/refman/8.0/en/create-user.html

Rajasekhar Amudala

   Rajasekhar Amudala

Master of Business Administration (MBA)
Oracle 10g Certified Professional (OCP)
Oracle 11g Certified Professional (OCP)
Oracle 10g RAC Certified Expert (OCE)
Oracle 11g RAC Certified Expert (OCE)
Oracle Golden Gate Certified
Oracle Exadata Certified
OCI Architect Professional
About me - Rajasekhar Amudala