MySQL Walkthrough: Adding accounts, granting permissions, deleting users

Source: Internet
Author: User

1. Add an account:

# Create a testuser account with a password of 123456 # If you do not write "identified by ' 123456 '" creates a TestUser account with a blank password mysql> create user testuser identified by ' 123456 '; # Refresh permissions Change mysql> flush privileges;

2. Granting permissions

# Grant all permissions for the TestUser account to access all databases locally mysql> grant all privileges on * * to ' testuser ' @ ' localhost ' identified by ' 123456 '; MySQL > Flush Privileges;

Command format:

Grant Privilegescode on Dbname.tablename to username@host identified by "password";

privilegesCodeRepresents the type of permission granted, which is commonly used in the following categories:
all privileges: All permissions;
select: Read permission;
delete: Delete permission;
update: Update permissions;
create: Create permissions;
drop: Delete database, data table permissions.

The complete permission type is as follows:

           Select_priv:y           insert_priv:y           update_priv:y           delete_priv:y           create_priv:y             drop_priv:y           Reload_priv:y         shutdown_priv:y          process_priv:y             file_priv:y            grant_priv:y       references_priv:y            index_priv:y            Alter_priv:y          show_db_priv:y            super_priv:y create_tmp_table_priv:y      lock_tables_priv:y          Execute _priv:y       repl_slave_priv:y      repl_client_priv:y      create_view_priv:y        show_view_priv:y   Create_routine_priv:y    alter_routine_priv:y      create_user_priv:y            event_priv:y          trigger_priv: Ycreate_tablespace_priv:y

Read more about the official MySQL documentation

dbName.tableNameRepresents the specific library or table that is granted permissions, and the following options are commonly used:

*.*: Grant permissions to all tables for all databases on the database server;
dbName.*: Grant permissions to all tables in the dbname database;
dbName.dbTable: Grants permissions to dbtable tables in database dbname.

username@hostRepresents the granted user and the IP address that allows the user to log on. There are several types of host:

localhost: Only allow the user to log on locally and not remotely.
%: Allows you to log in remotely from any machine except this computer.
192.168.1.11: The specific IP means that only the user is allowed to log on from a specific IP.

identified by "password": Represents the password of the access user, and if none is available, the default password is blank.

To view the commands granted by the permission:

Mysql> Show grants for ' testuser ';

3. Delete a user

# Remove the drop user testuser@ ' localhost ' from the TestUser users who just created the local access permission;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.