How to connect to MySQL Without Root Password

MySQL is open source relational database management system. It is the world’s most popular database management system. It is ideal for both small as well as large application. It is written in C and C++ . When we install MySQL or MariaDB , it is recommended to set root user password for database to secure it. This password is used to access the database safely.  In this article i will explain how to connect to MySQL without password .

How to set root password in MySQL :

If you freshly installed MySQL on your server , you should set root user password to secure your database. you can set root password through command given below –

How to connect to MySQL without root password :

To run MySQL command without using password , you should define your user_name and password in ~/.my.cnf . This is user specific configuration file in user home directory . First  create configuration file and add the value as given below

you replace user_name and password with your user name and your password . Save and close the file. After that give permission to the file

Now this file is only readable and writable by you . No other user can edit this file.  when you run mysql command from command line , they will read user name and password from file you have created.

Now you can login to your database without password.

Through this topics i explained how to connect to MySQL without root password. I hope this is useful for you. Please subscribe to newsletter for updated articles. We will discuss about  other topics in next articles.