{"id":3376,"date":"2024-03-31T14:00:51","date_gmt":"2023-02-26T15:27:14","guid":{"rendered":""},"modified":"2025-02-02T00:46:20","modified_gmt":"2025-02-01T23:46:20","slug":"how-to-create-a-new-user-and-grant-permissions-in-mysql","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-create-a-new-user-and-grant-permissions-in-mysql\/","title":{"rendered":"How To Create a New User and Grant Permissions in MySQL"},"content":{"rendered":"<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<header>\n<h1>How To Create a New User and Grant Permissions in MySQL<\/h1>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>MySQL is one of the most popular relational database management systems used for storing and managing data. When working with MySQL, it&#8217;s essential to create users with specific permissions to ensure security and proper access control. In this guide, we&#8217;ll walk you through the steps to create a new user and grant permissions in MySQL.<\/p>\n<\/section>\n<section>\n<h2>Step 1: Access MySQL as the Root User<\/h2>\n<p>To create a new user and grant permissions, you need to access MySQL as the root user or another user with administrative privileges. Use the following command to log in:<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>You&#8217;ll be prompted to enter the root password. Once logged in, you can proceed to create a new user.<\/p>\n<\/section>\n<section>\n<h2>Step 2: Create a New User<\/h2>\n<p>To create a new user, use the <code>CREATE USER<\/code> statement. Replace <code>username<\/code> and <code>password<\/code> with your desired credentials:<\/p>\n<pre><code>CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';<\/code><\/pre>\n<p>If you want to allow the user to connect from any host, replace <code>localhost<\/code> with <code>%<\/code>:<\/p>\n<pre><code>CREATE USER 'username'@'%' IDENTIFIED BY 'password';<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 3: Grant Permissions to the User<\/h2>\n<p>After creating the user, you need to grant them specific permissions. Use the <code>GRANT<\/code> statement to assign privileges. For example, to grant all privileges on a specific database, use the following command:<\/p>\n<pre><code>GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';<\/code><\/pre>\n<p>If you want to grant specific privileges, such as <code>SELECT<\/code>, <code>INSERT<\/code>, and <code>UPDATE<\/code>, you can specify them like this:<\/p>\n<pre><code>GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'username'@'localhost';<\/code><\/pre>\n<p>After granting permissions, run the following command to apply the changes:<\/p>\n<pre><code>FLUSH PRIVILEGES;<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 4: Verify User Permissions<\/h2>\n<p>To verify the permissions granted to the user, use the <code>SHOW GRANTS<\/code> statement:<\/p>\n<pre><code>SHOW GRANTS FOR 'username'@'localhost';<\/code><\/pre>\n<p>This will display a list of all permissions assigned to the user.<\/p>\n<\/section>\n<section>\n<h2>Step 5: Remove a User (Optional)<\/h2>\n<p>If you need to remove a user, use the <code>DROP USER<\/code> statement:<\/p>\n<pre><code>DROP USER 'username'@'localhost';<\/code><\/pre>\n<p>This will delete the user and revoke all their permissions.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>Creating a new user and granting permissions in MySQL is a fundamental task for database administrators. By following the steps outlined in this guide, you can ensure that your database is secure and that users have the appropriate level of access.<\/p>\n<p>If you&#8217;re looking for a reliable hosting solution to manage your MySQL databases, consider \u00a0<a href=\"https:\/\/ie.netcloud24.com\"><strong>free webhosting<\/strong><\/a> options to help you get started quickly.<\/p>\n<\/section>\n<footer>\n<p>\u00a0<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 How To Create a New User and Grant Permissions in MySQL Introduction MySQL is one of the most popular relational database management systems used for storing\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-3376","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=3376"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3376\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=3376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=3376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=3376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}