Save that file for further reference as ~/MySQL-password. Executing the above command gives the following output – We can also use this command to set up the password of the root user in the following way: ALTER USER IDENTIFIED BY 'a' Ī is the new password that we wish to assign. You can change the password of any user using the ALTER command. Using ALTER command to change the password of the user That asks you multiple questions whose answers will set all the properties you wish to assign. This command can be used in the following way by simply typing mysql_secure_connection That is way more secure and advanced as it not only allows you to set the password for the root user but also gives the facility to add and set many certain features to your MySQL database, such as restricting the login of the root user from remote machines, anonymous users can be removed, and the test database can also be removed. We can use the alternative mysql_secure_connection command instead of mysqladmin. But suppose that for some reason, it was not requested, and now you wish to set the password, then you can make use of the mysqladmin command in the following way to assign the new password to the root user – sudo mysqladmin -u root password myPassWhichIWant Using mysqladmin commandīy default, a password is asked during the installation of MySQL for the root user. ![]() We will see all the methods one by one in detail. There are multiple ways in which we can change the root user’s password in case you have forgotten the current password or wish to set up a stronger password. ![]() Now, let us see how to set the root user’s password or change the existing password. ![]() Setting up the password for the root user The configuration file called my.cnf or mysqld.cnf, which is stored in the directory /etc/MySQL//mysqld.cnf already contains this information. You can describe the user table and see the list of the columns stored in the user table using the following command – desc user Īfter selecting these columns for the root user, you will observe that the root user has almost all the privileges assigned to it and have a ‘Y’ value stored in the privilege column that stands for yes.Īlternatively, one more command can be used to login as the root user into a MySQL database that is as follows – sudo -i mysqlĪt this point, you don’t need to provide your username or password. Many properties and informatical fields are stored n the user table for all the user-related information. The database already had it upon installation. I did not create the root user, unlike the newUserForRep user. We can see that the user root is present in the database with the local host as the host. The execution of the above query gives the following output – Now, we will fire the select query on the user table in the MySQL database using the following query statement – select user, host from a user That gives the following output after execution – ![]() Now, we will specify that we have to use the MySQL database using the following command – use MySQL Let us first check all the databases using the following command – Show Databases The MySQL database automatically generates the user table and stores the users’ data in it. Let us know the list of users in my MySQL database server. Now, you will see the MySQL shell and work on your database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |