{"id":163,"date":"2015-07-27T14:40:06","date_gmt":"2015-07-27T09:10:06","guid":{"rendered":"https:\/\/bhuvan.wordpress.com\/?p=163"},"modified":"2025-07-15T19:40:45","modified_gmt":"2025-07-15T14:10:45","slug":"creating-a-mysql-db-user-and-set-password-to-it-from-cli","status":"publish","type":"post","link":"https:\/\/www.bhuvankrishna.in\/blog\/2015\/07\/27\/creating-a-mysql-db-user-and-set-password-to-it-from-cli\/","title":{"rendered":"Creating a mysql db, user and set password to it from cli"},"content":{"rendered":"<p>While developing a CMS we don&#8217;t have phpmyadmin, plesk or cpanel rather a simple cli. So to create a quick DB with a user who has all privileges to the DB and a password to the user just give these commands. this method will works for mariadb too.<\/p>\n<pre>$ mysql -u adminusername -p\nEnter password:\nWelcome to the MySQL monitor.\u00a0 Commands end with ; or g.\nYour MySQL connection id is 13\nServer version: 5.6.25-3 (Debian)\n\nCopyright (c) 2000, 2015, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\n\nmysql&gt; CREATE DATABASE databasename;\nQuery OK, 1 row affected (0.00 sec)\n\nmysql&gt; CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';\nQuery OK, 0 rows affected (0.00 sec)\n \nmysql&gt; GRANT ALL PRIVILEGES ON databasename.* TO \"username\"@\"hostname\";\nQuery OK, 0 rows affected (0.00 sec)\n  \nmysql&gt; FLUSH PRIVILEGES;\nQuery OK, 0 rows affected (0.01 sec)\n\nmysql&gt; EXIT\nBye\n$<\/pre>\n<p>For reseting root password<\/p>\n<pre>MariaDB [(none)]&gt; use mysql;\nMariaDB [(none)]&gt; update user set password=PASSWORD(\"NEWPASSWORD\") where User='root';\n<\/pre>\n<p>Don&#8217;t forget to replace NEWPASSWORD with new password<\/p>\n<p>Reset root password another way<\/p>\n<pre>MariaDB [(none)]&gt; ALTER USER 'root'@'localhost' IDENTIFIED BY '&lt;PASSWORD&gt;';<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While developing a CMS we don&#8217;t have phpmyadmin, plesk or cpanel rather a simple cli. So to create a quick DB with a user who has all privileges to the DB and a password to the user just give these commands. this method will works for mariadb too. $ mysql -u adminusername -p Enter password:\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.bhuvankrishna.in\/blog\/2015\/07\/27\/creating-a-mysql-db-user-and-set-password-to-it-from-cli\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":4,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":601,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/163\/revisions\/601"}],"wp:attachment":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}