Create a new MySQL user Account
mysql > CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Change a MYSQl user
account password
If you have MySQL 5.7.6 and newer or
MariaDB 10.1.20 and newer, to change the password use the following command:
You can find your server version by
issuing the following command:
mysql> select version()
+-----------+
| version() |
+-----------+
| 5.7.25
|
+-----------+
Mysql > ALTER USER 'database_user'@'localhost'
IDENTIFIED BY 'new_password';
If you have MySQL 5.7.5 and older or
MariaDB 10.1.20 and older, then use:
Mysql> SET PASSWORD
FOR 'database_user'@'localhost' = PASSWORD('new_password');
List all MySql user accounts
mysql> SELECT user,
host FROM mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| lotus | % |
| test123 | % |
| beta | localhost |
| com | localhost |
| fin | localhost |
| ind | localhost |
| lotus | localhost |
| mysql.session |
localhost |
| mysql.sys | localhost |
| root | localhost |
| test123 | localhost |
| test_test | localhost |
+---------------+-----------+
12 rows in set (0.00
sec)
Delete MYSql user acoount :
MYSQL > DROP USER
'database_user@'localhost';
Grant Permissions to a MYSQL user account
To grand all privileges to a user
account over a specific database, use the following command:
MYSQl > GRANT ALL
PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
To grand all privileges to a user
account over all databases, use the following command:
MYSQL > GRANT ALL
PRIVILEGES ON *.* TO 'database_user'@'localhost';
To grand all privileges to a user
account over a specific table from a database, use the following command:
MYSQL > GRANT ALL
PRIVILEGES ON database_name.table_name TO 'database_user'@'localhost';
If
you want to grant only specific privileges to a user account over a specific
database type:
MYSQL > GRANT SELECT, INSERT, DELETE ON database_name.* TO database_user@'localhost';
Revoke permissions from a MYSQL user account
MQSQL > REVOKE ALL
PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
Remove An Existing MYSQL User Account
DROP USER
'user'@'localhost';