{"id":59,"date":"2018-04-24T05:42:36","date_gmt":"2018-04-24T05:42:36","guid":{"rendered":"http:\/\/td_uid_10_5adec3cc211e7"},"modified":"2018-06-01T04:01:22","modified_gmt":"2018-06-01T04:01:22","slug":"how-to-create-a-new-user-and-grant-permissions-in-mysql","status":"publish","type":"post","link":"https:\/\/forumweb.hosting\/blog\/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><a href=\"https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/How-To-Create-a-New-User-and-Grant-Permissions-in-MySQL.jpg\"><img loading=\"lazy\" class=\"wp-image-538  alignleft\" src=\"https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/How-To-Create-a-New-User-and-Grant-Permissions-in-MySQL.jpg\" alt=\"\" width=\"341\" height=\"215\" srcset=\"https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/How-To-Create-a-New-User-and-Grant-Permissions-in-MySQL.jpg 589w, https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/How-To-Create-a-New-User-and-Grant-Permissions-in-MySQL-300x189.jpg 300w\" sizes=\"(max-width: 341px) 100vw, 341px\" \/><\/a>If you have ever developed a web or application, you may need mysql database. Databases are the virtual storage that is needed to build a web application. They are used to store user information, such as username, password, email address, and so on. Basically, any information you want to store for future use may be stored in databases.<\/p>\n<p>Of course, this data must be stored in order. Therefore the data management system should be used. These systems communicate with the database and allow programmers to structure, store, back up, and edit data.<\/p>\n<p>MySQL is one such database management system. It is one of the most popular systems, because of its ease of use and supported by a large community. In fact, its popularity attracts many large companies such as Facebook or Twitter to a certain extent.<\/p>\n<p>In this tutorial, we will go through the basics of the MySQL Database and show you how to create a user in the MySQL Database. You will also learn how to assign permissions to MySQL users. The command line will be used in this tutorial.<\/p>\n<p><strong>Step 1 &#8211; Create MySQL User for MySQL database and assign all permissions<\/strong><\/p>\n<p>Once you start using the MySQL database, you will be provided with a username and password. These credentials will give you &#8220;root access&#8221;. A root user has full access to database and tables in the databases.<\/p>\n<p>But over time, you will need to give access to the database to someone else without allowing them full use. For example, companies that hire programmers to maintain the database, but do not want them to have the right to delete or edit sensitive information, will need to provide a non-root user login. This way, the company has control over the programmer who can and can not do with the data.<\/p>\n<p>Creating a new user is also very simple in MySQL. We will tell you how to create a MySQL user and how to assign full privileges to your database. In fact, it&#8217;s not a good idea to assign permissions to a user &#8211; not root, but it&#8217;s the easiest way for beginners. To create a new user, follow these steps:<\/p>\n<ol>\n<li>Access the command line and fill the MySQL server:<\/li>\n<\/ol>\n<blockquote class=\"td_quote_box td_box_left\"><p>mysql<\/p><\/blockquote>\n<p>2. If you want to execute these commands on the VPS server, you will need to make a connection to SSH and run this command.<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>CREATE USER &#8216;non-root&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;123&#8217;;<\/p><\/blockquote>\n<p>With this command, &#8216;non-root&#8217; is the name of the new user and &#8216;123&#8217; is the password for this user. You need to replace two values \u200b\u200bwith your own information, in parentheses.<\/p>\n<p>3. Just creating this user is not enough. You need to assign permissions to it. To assign full privileges to the newly created user, execute the following command:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>GRANT ALL PRIVILEGES ON * . * TO &#8216;non-root&#8217;@&#8217;localhost&#8217;;<\/p><\/blockquote>\n<p>4. For a change to take place immediately, use the following command:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>FLUSH PRIVILEGES;<\/p><\/blockquote>\n<p>It is done! Your newly created user has full rights as the user root<\/p>\n<p><strong>Step 2 &#8211; Assign certain permissions to the MySQL user<\/strong><\/p>\n<p>As mentioned above, it is not safe to assign root privileges to a non-root user. Over time, you will need to assign each permission level to each user type. MySQL allows you to assign permissions to a user with a simple command line:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>GRANT [permission type] ON [database name].[table name] TO \u2018non-root\u2019@&#8217;localhost\u2019;<\/p><\/blockquote>\n<p>You simply replace &#8216;permission type&#8217; with the value of the permissions you want to assign to the user. You must also specify the database and table name that you want to grant non-root user permissions. The same as the example on &#8216;non-roo&#8217; should be replaced instead of the one you specify:<\/p>\n<p>MySQL has a variety of permissions, listed below<\/p>\n<p>CREATE &#8211; Allows the user to create databases\/tables<br \/>\nSELECT &#8211; Allows the user to access the data<br \/>\nINSERT &#8211; Allows users to create rows in the table<br \/>\nUPDATE &#8211; Allows the user to edit the entries in the table<br \/>\nDELETE &#8211; Allows users to delete entries in the table<br \/>\nDROP &#8211; Allows the user to completely delete the table\/database<br \/>\nTo use the options just replace [permission type] with the appropriate keywords. To apply different types of permissions, exclude them with commas. For example, you can assign CREATE and SELECT permissions to a non-root user database with the following command:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>GRANT CREATE, SELECT ON * . * TO &#8216;non-root&#8217;@&#8217;localhost&#8217;;<\/p><\/blockquote>\n<p>Of course, you will also need to recover the permissions granted to a user. You can do this with the following command:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>REVOKE [permission type] ON [database name]. [Table name] FROM &#8216;non-root&#8217; @ &#8216;localhost&#8217;;<\/p><\/blockquote>\n<p>For example, to recover all permissions for a non-root user:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>REVOKE ALL PRIVILEGES ON *.* FROM &#8216;non-root&#8217;@&#8217;localhost&#8217;;<\/p><\/blockquote>\n<p>Finally, you can delete the user:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>DROP USER \u2018non-root\u2019@\u2018localhost\u2019;<\/p><\/blockquote>\n<p>Remember, in order to execute these permissions you need root privileges. Also, be sure to execute FLUSH PRIVILEGES after making any changes to the permissions.<\/p>\n<p><strong>Conclude<\/strong><br \/>\nIn this tutorial, we learned the basic permissions of MySQL database, and how to create a new MySQL user. In particular, we learn about:<\/p>\n<p>Create new user and assign full privileges<br \/>\nAssign certain permissions to users, and revoke permissions and delete users.<br \/>\nAssigning permissions is a fundamental step in developing a web application, however, it is an effective security measure for managing the database and operating it. Most modern applications depend on the database, which makes MySQL database privilege assign\/retrieve the most important.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have ever developed a web or application, you may need mysql database. Databases are the virtual storage that is needed to build a web application. They are used to store user information, such as username, password, email address, and so on. Basically, any information you want to store for future use may be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":538,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[65],"_links":{"self":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":7,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions\/539"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/media\/538"}],"wp:attachment":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}