{"id":3469,"date":"2019-01-23T18:14:37","date_gmt":"2019-01-23T12:44:37","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=3469"},"modified":"2026-10-05T17:26:20","modified_gmt":"2026-10-05T11:56:20","slug":"create-new-user-grant-permissions-mysql","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/create-new-user-grant-permissions-mysql\/","title":{"rendered":"How to Create a New User and Grant Permissions in MySQL"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a new user and grant permissions in MySQL<\/strong> to securely manage database access for applications, websites, and other services. MySQL is a popular open-source relational database management system used to store and manage application data. Creating a new MySQL user and assigning the required permissions is an important task for database administrators and developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will explain how to create a new user and grant permissions in MySQL, including granting access to all databases, granting access to a specific database, and revoking permissions when required.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before creating a new MySQL user and granting permissions, make sure you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Root or administrative access to the MySQL server.<\/li>\n\n\n\n<li>Access to the MySQL command-line shell.<\/li>\n\n\n\n<li>MySQL installed and running on the server.<\/li>\n\n\n\n<li>The required username and password for the new MySQL user.<\/li>\n\n\n\n<li>The name of the database if you want to grant access to a specific database.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL, the most popular open-source SQL database management system, is developed, distributed, and supported by Oracle Corporation.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1:\u00a0<\/strong>A new user can be created within the MySQL shell using the following statement:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>CREATE USER '<strong>pheonix<\/strong>'@'localhost' IDENTIFIED BY '<strong>password<\/strong>';<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will create a new user named \u2018pheonix\u2019 without any permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2:<\/strong> To give full access to all databases for the pheonix user, run the following statement:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GRANT ALL PRIVILEGES ON * . * TO '<strong>pheonix<\/strong>'@'localhost';<\/code><br><br><strong>Step 3:<\/strong>Then run the following statement to reload all the privileges:<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>FLUSH PRIVILEGES;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4:&nbsp;<\/strong>To give access to a specific database for the new user, run the following statement:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GRANT ALL PRIVILEGES ON&nbsp;<strong>database<\/strong>&nbsp;. * TO '<strong>pheonix<\/strong>'@'localhost';<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 5: <\/strong>To revoke access:<br><br><code>REVOKE\u00a0ALL PRIVILEGES ON\u00a0<strong>database<\/strong>.* FROM '<strong>pheonix<\/strong>'@'localhost';<\/code><br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating a new MySQL user and granting the appropriate permissions helps manage database access securely and efficiently. Using the <code>CREATE USER<\/code>, <code>GRANT<\/code>, and <code>REVOKE<\/code> statements, you can control which databases a user can access and what actions they can perform. It is recommended to grant users only the permissions they require to follow the principle of least privilege and improve MySQL database security.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For detailed information about MySQL account management and user privileges, refer to the official <strong>MySQL documentation<\/strong> <a href=\"https:\/\/dev.mysql.com\/doc\" target=\"_blank\" rel=\"noopener\">Link<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. How do I create a new user in MySQL?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can create a new MySQL user using the <code>CREATE USER<\/code> statement:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. How do I grant all privileges to a MySQL user?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>GRANT ALL PRIVILEGES<\/code> statement:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This grants the user full privileges on all databases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. How do I grant access to a specific database in MySQL?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can grant privileges to a specific database using:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>database<\/code> with the name of the required database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/configuring-mysql-to-listen-on-a-private-ip-address\/\">Configuring MySQL to Listen on a Private IP Address<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-disable-lock-a-mysql-user-account-from-cli\/\">How to Disable\/Lock a MySQL User Account from CLI?<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-copy-a-table-from-one-database-to-another-in-mysql\/\">How to Copy a Table from One Database to Another in MySQL?<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Need Help with MySQL User Management?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Having trouble creating MySQL users or managing database permissions? Our experts can help you configure MySQL users, privileges, and database access securely and efficiently. Get in touch with our team\u00a0<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Create a new user and grant permissions in MySQL to securely manage database access for applications, websites, and other [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"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},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[179],"class_list":["post-3469","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-mysql-2","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-TX","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=3469"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3469\/revisions"}],"predecessor-version":[{"id":12115,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3469\/revisions\/12115"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}