{"id":11556,"date":"2019-03-14T12:18:27","date_gmt":"2019-03-14T12:18:27","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11556"},"modified":"2019-03-14T12:18:27","modified_gmt":"2019-03-14T12:18:27","slug":"how-to-connect-to-mysql-without-root-password-on-terminal","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/how-to-connect-to-mysql-without-root-password-on-terminal\/","title":{"rendered":"How to Connect to MySQL Without Root Password on Terminal"},"content":{"rendered":"<p>Normally while installing\u00a0<strong>MySQL\/MariaDB<\/strong>\u00a0database server on Linux, it\u2019s recommended to set a MySQL root user password to secure it, and this password is required to access the database server with root user privileges.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/install-mariadb-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">How to Install and Secure MariaDB 10 in CentOS 7<\/a><\/p>\n<p>In this guide, we will show you how to connect and run MySQL commands without entering a password (mysql passwordless root login) on the Linux terminal.<\/p>\n<h3>How to Set MySQL Root Password<\/h3>\n<p>In case you have freshly installed the MySQL\/MariaDB server, then it doesn\u2019t require any password to connect to it as root user. To secure it, set the MySQL\/MariaDB password for root user with the following command.<\/p>\n<p>Note that this command is just one of the many\u00a0<a href=\"https:\/\/www.tecmint.com\/mysqladmin-commands-for-database-administration-in-linux\/\" target=\"_blank\" rel=\"noopener\">MySQL (Mysqladmin) Commands for Database Administration<\/a>in Linux.<\/p>\n<pre># mysqladmin -u root password <strong>YOURNEWPASSWORD<\/strong>\r\n<\/pre>\n<h3>How to Connect or Run MySQL Without Root Password<\/h3>\n<p>To run MySQL commands without entering password on the terminal, you can store your user and password in the\u00a0<code>~\/.my.cnf<\/code>\u00a0user specific configuration file in user\u2019s home directory as described below.<\/p>\n<p>Now create the config file\u00a0<code>~\/.my.cnf<\/code>\u00a0and add configurations below in it (remember to replace\u00a0<strong>mysqluser<\/strong>\u00a0and\u00a0<strong>mysqlpasswd<\/strong>\u00a0with your own values).<\/p>\n<pre>[mysql]\r\nuser=user\r\npassword=password\r\n<\/pre>\n<p>Save and close the file. Then set the suitable permissions on it, to make it only readable and writable by you.<\/p>\n<pre># chmod 0600 .my.cnf\r\n<\/pre>\n<p>Once you have set user and password in the Mysql configuration file, from now on when you run mysql commands such as mysql, mysqladmin etc, they will read the mysqluser and mysqlpasswd from the above file.<\/p>\n<pre># mysql \r\n# mysql -u root \r\n<\/pre>\n<div id=\"attachment_26623\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/08\/Run-Mysql-Without-Root-Password.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26623\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/08\/Run-Mysql-Without-Root-Password.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/08\/Run-Mysql-Without-Root-Password.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/08\/Run-Mysql-Without-Root-Password-768x621.png 768w\" alt=\"Run Mysql- Commands Without Root Password\" width=\"802\" height=\"648\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run Mysql- Commands Without Root Password<\/p>\n<\/div>\n<p>You may also like to read these related articles about MySQL\/MariaDB:<\/p>\n<ol>\n<li>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/mysqladmin-commands-for-database-administration-in-linux\/\" target=\"_blank\" rel=\"noopener\">20 MySQL (Mysqladmin) Commands for Database Administration in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/change-mysql-mariadb-root-password\/\" target=\"_blank\" rel=\"noopener\">How to Change Root Password of MySQL or MariaDB in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/reset-mysql-or-mariadb-root-password\/\" target=\"_blank\" rel=\"noopener\">How to Reset MySQL or MariaDB Root Password in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/mysql-mariadb-performance-tuning-and-optimization\/2\/\" target=\"_blank\" rel=\"noopener\">15 Useful MySQL\/MariaDB Performance Tuning and Optimization Tips<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/mysql-performance-monitoring\/\" target=\"_blank\" rel=\"noopener\">4 Useful Commandline Tools to Monitor MySQL Performance in Linux<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>In this guide, we showed how to run MySQL commands without entering root password on the terminal. If you have any queries or thoughts to share, do hit us up via the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/connect-to-mysql-without-root-password\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Normally while installing\u00a0MySQL\/MariaDB\u00a0database server on Linux, it\u2019s recommended to set a MySQL root user password to secure it, and this password is required to access the database server with root user privileges. Suggested Read:\u00a0How to Install and Secure MariaDB 10 in CentOS 7 In this guide, we will show you how to connect and run &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/how-to-connect-to-mysql-without-root-password-on-terminal\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Connect to MySQL Without Root Password on Terminal&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11556","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11556"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11556\/revisions"}],"predecessor-version":[{"id":11557,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11556\/revisions\/11557"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}