Home Database Mysql Tutorial How to increase permissions in mysql

How to increase permissions in mysql

Apr 12, 2022 pm 03:25 PM
mysql

The GRANT statement can be used in mysql to add permissions to users. The syntax is "GRANT permission type ON permission level value TO user [IDENTIFIED BY 'password'] [WITH clause];"; where the parameter "user" represents the user account , the format is "'username'@'hostname'".

How to increase permissions in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In MySQL, you can use the GRANT statement to authorize users and increase their permissions.

The syntax format is as follows:

GRANT priv_type [(column_list)] ON database.table
TO user [IDENTIFIED BY 'password']
[WITH with_option [with_option]...]
Copy after login

Among them:

  • priv_type parameter indicates the permission type;

  • The columns_list parameter indicates which columns the permissions apply to. When this parameter is omitted, it means it applies to the entire table;

  • database.table is used to specify the level of permissions;

  • The user parameter represents the user account, which is composed of user name and host name. The format is "'username'@'hostname'";

  • IDENTIFIED BY parameter is used to set the user name Password;

  • # The password parameter is the user's new password.

The permissions that can be granted in MySQL are as follows:

  • Column permissions are related to a specific column in the table. For example, you can use the UPDATE statement to update permissions on the value of the name column in the students table.

  • Table permissions are related to all data in a specific table. For example, you can use the SELECT statement to query the permissions for all data in the students table.

  • Database permissions are related to all tables in a specific database. For example, you can create new tables in the existing database mytest.

  • User permissions are related to all databases in MySQL. For example, you can delete an existing database or create a new database.

Correspondingly, the values ​​that can be used to specify the permission level in the GRANT statement have the following formats:

  • *: indicates the current database of all tables.

  • *.*: Indicates all tables in all databases.

  • db_name.*: Indicates all tables in a database, db_name specifies the database name.

  • db_name.tbl_name: Represents a table or view in a database, db_name specifies the database name, tbl_name specifies the table name or view name.

  • db_name.routine_name: Represents a stored procedure or function in a database, routine_name specifies the stored procedure name or function name.

  • TO clause: If permission is granted to a user that does not exist, MySQL will automatically execute a CREATE USER statement to create the user, but a password must be set for the user.

In MySQL, only users with GRANT permissions can execute GRANT statements.

Example:

Use the GRANT statement to create a new user testUser with the password testPwd. User testUser has query and insert permissions on all data, and is granted GRANT permissions.

mysql> GRANT SELECT,INSERT ON *.*
    -> TO 'testUser'@'localhost'
    -> IDENTIFIED BY 'testPwd'
    -> WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.05 sec)
Copy after login

Use the SHOW GRANTS statement to query the permissions of user testUser, as shown below.

How to increase permissions in mysql

Extended knowledge: Permission type description

1) When granting database permissions, the can be specified as the following value:

Permission name corresponds to the field in the user table Description
SELECT Select_priv means granting the user permission to use the SELECT statement to access all tables and views in a specific database.
INSERT Insert_priv Indicates that the user is granted permission to use the INSERT statement to add data rows to all tables in a specific database.
DELETE Delete_priv Indicates that the user is granted permission to use the DELETE statement to delete data rows from all tables in a specific database.
UPDATE Update_priv means granting the user permission to use the UPDATE statement to update the values ​​of all data tables in a specific database.
REFERENCES References_priv indicates that the user is granted permission to create foreign keys pointing to tables in a specific database.
CREATE Create_priv Represents the authority that authorizes a user to create a new table in a specific database using the CREATE TABLE statement.
ALTER Alter_priv Indicates that the user is granted permission to use the ALTER TABLE statement to modify all data tables in a specific database.
SHOW VIEW Show_view_priv Indicates that the user is granted permission to view the view definitions of existing views in a specific database.
CREATE ROUTINE Create_routine_priv means granting the user permission to create stored procedures and stored functions for a specific database.
ALTER ROUTINE Alter_routine_priv indicates that the user is granted permission to update and delete existing stored procedures and stored functions in the database.
INDEX Index_priv indicates that the user is granted permission to define and delete indexes on all data tables in a specific database.
DROP Drop_priv means granting the user permission to delete all tables and views in a specific database.
CREATE TEMPORARY TABLES Create_tmp_table_priv Indicates that the user is granted permission to create temporary tables in a specific database.
CREATE VIEW Create_view_priv means granting the user permission to create new views in a specific database.
EXECUTE ROUTINE Execute_priv means granting the user permission to call stored procedures and stored functions of a specific database.
LOCK TABLES Lock_tables_priv indicates that the user is granted permission to lock existing data tables of a specific database.
ALL or ALL PRIVILEGES or SUPER Super_priv means all the above permissions/super permissions

2) When granting table permissions, can be specified as the following value:

Permission name corresponds to the user table Field Description
SELECT Select_priv Grants users permission to access specific tables using the SELECT statement
INSERT Insert_priv Grants the user permission to add rows to a specific table using the INSERT statement
DELETE Delete_priv Grants the user permission to delete data rows from a specific table using the DELETE statement
DROP Drop_priv Grant users the permission to delete data tables
UPDATE Update_priv Grant users the permission to update specific data tables using the UPDATE statement Permissions
ALTER Alter_priv Grants users permission to use the ALTER TABLE statement to modify the data table
REFERENCES References_priv Grants the user permission to create a foreign key to reference a specific data table
CREATE Create_priv Grants the user permission to create a data table using a specific name
INDEX Index_priv Grants the user the permission to create a data table in the table Permissions defined on the index
ALL or ALL PRIVILEGES or SUPER Super_priv All permission names

3) When granting column permissions, the value of can only be specified as SELECT, INSERT and UPDATE, and the column name list column-list needs to be added after the permissions.

4) The most efficient permission is user permission.

When granting user permissions, the can be specified as all the values ​​when granting database permissions, and can also be the following values:

  • ## CREATE USER: Indicates that the user is granted permission to create and delete new users.

  • SHOW DATABASES: Indicates that the user is granted permission to use the SHOW DATABASES statement to view the definitions of all existing databases.

[Related recommendations:

mysql video tutorial]

The above is the detailed content of How to increase permissions in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

See all articles