When MySQL is first installed on the machine, you can access the database anonymously or as root without a password. Also, if you are an administrator, you need to build and authorize some users, which involves setting up a password. Here's how to set a password:
First we should know that the password store in the MySQL database must be encrypted with the password () function. Because passwords are stored in encrypted form in the user table, not as plain text. If you do not encrypt, execute the following statement directly in the database:
Use MySQL
Insert into User (Host,user,password) values ('% ', ' user_name ', ' your password ');
Flush privileges;
I believe the result will not satisfy you. Because the server is comparing encrypted values, the server connection must fail. Here is the flush privileges; This command reloads the authorization table. You can also use mysqladmin-u root directly under the shell. Reload or mysqladmin-u root flush-privileges to implement overloaded authorization tables.
In the MySQL environment, you can use the following statement to set the password:
1.insert into User (Host,user,password) values ('% ', ' user_name ', password ("Your password");
2.set password for user_name = password ("Your password")
Both of these methods must be overloaded with authorization tables.
3. Of course, you can also set the password directly when creating a user, and the grant statement will automatically encrypt the password for you.
such as: Grant all on *.* to user_name@% identified by "Your password";
In addition, you can use the Mysqladmin program to set the password in the shell environment.
such as: mysqladmin-u root password "Your password"