MySQL multiple ways to modify the root password + empower remote login

MySQL multiple ways to modify the root password + empower remote login

1. There are many ways
for MySQL to modify the root password. Directly execute SET PASSWORD FOR'root'@'localhost' = PASSWORD('newpass'); under Navicat for MySQL;

Method 1: Use the SET PASSWORD command

  mysql -u root
format: mysql> set password for username
@localhost = password(' new password'); Example: mysql> set password for root@localhost = password('1234');

Method 2: Use mysqladmin to change only localhost

  Format: mysqladmin -u username -p old password password new password. There is no space between p and the old password. For example,
  1. If root has no password, add a password of 123 to root. First enter the directory mysql\bin under DOS, and then type the following command
[root@BI-162 ~]# mysqladmin -u root password 123
  2. If root has already set a password, change the root password to 234 p and the old password does not Space
[root@BI-162 ~]# mysqladmin -u root -p123 password 1234

Method 3: Use UPDATE to directly edit the user table

  mysql -u root -p
  mysql> use mysql;
  mysql> UPDATE user SET password = PASSWORD('新密码') WHERE user = 'root';
  mysql> FLUSH PRIVILEGES;

Or set local and remote login passwords separately, the passwords can be different
mysql> update mysql.user set password=password('123') where user='root' and host='localhost';
mysql> update mysql.user set password=password ('123') where user='root' and host='%';
update mysql.user set password=password('123') where user='root' and host='BI-162';
mysql> flush privileges ;

Method 4: When you forget the root password, you can
kill the MySQL process in the system like this ;
  mysqld_safe --skip-grant-tables&
  mysql -u root mysql
  mysql> UPDATE user SET password=PASSWORD('new password') WHERE user= 'root';
  mysql> flush privileges;

Method 4: When forget the root password, it can be
to windows as an example:

  1. Shut down the running MySQL service.
  2. Open a DOS window and go to the mysql\bin directory.
  3. Type mysqld --skip-grant-tables and press Enter. --skip-grant-tables means to skip the authorization table authentication when starting the MySQL service.
  4. Open another DOS window (because the DOS window just now can no longer be moved), and go to the mysql\bin directory.
  5. Enter mysql and press Enter. If successful, the MySQL prompt> will appear.
  6. Connect to the authority database: use mysql;.
  7. Change password: update user set password=password('123') where user='root'; (don't forget to add a semicolon at the end).
  8. Flush privileges (required steps): flush privileges;.
  9. Exit quit.
  10. Log out of the system, enter again, and log in with the username root and the new password 123 just set.

2. Empower the remote server to
allow users to log in remotely at the specified IP. If you want to not restrict the IP of the link, set it to "%" to
grant all PRIVILEGES on bidb. to root@'%' identified by '123';
grant all PRIVILEGES on pacs.
to root@'%' identified by '123';
grant all PRIVILEGES on mysql. to root@'%' identified by '123';
grant all PRIVILEGES on test_db.
to root@'192.168.1.101' identified by '123456';
grant all on . to root@'%' identified by'root' with grant option;

mysql -u root -p
mysql> use mysql;
mysql>select host, user, password from user; In
addition, from this user table, we can build such a permission system. The same user name uses different passwords when logging in from different machines.

Guess you like

Origin blog.51cto.com/13293070/2668477