Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change password in mysql 5.1and log in to mysql database remotely

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following together to understand how to modify the password in mysql 5.1, and remote login mysql database, I believe we will certainly benefit a lot after reading, the text is not more refined, I hope mysql 5.1 how to modify the password, and remote login mysql database This short content is what you want.

mysql creates users and authorizes:

Format: grant permissions on database name. table name to user @ login host identified by "user password";

grant[English][gr $>:nt] recognition; consent; grant; grant; grant

Example 1: Allow mk user to log in from localhost

mysql> grant all on book.* to mk1@localhost identified by "123456";

#Allow access to all tables under book database, only book tables, and users of the same Cloud Virtual Machine

Allow mk2 users to connect to mysql Cloud Virtual Machine from any remote host:

mysql> grant all privileges on *.* to mk2@'%' identified by '123456' with grant option;

# with grant option means that mk2 users can delegate their privileges to newly created users. In addition, it is OK to add privileges or not. % refers to any remote host, excluding local addresses and localhost

Flush privileges; Refresh database

Testing:

[root@xuegod64 ~]# mysql -u mk2 -h 192.168.1.63 -p123456

mysql> #login normal

However:

[root@xuegod63 ~]# mysql -u mk2 -h 192.168.1.63-p123456 #Cannot log in

Solution:

mysql> grant all privileges on *.* to 'mk2'@'192.168.1.63' identified by '123456' with grant option;

[root@xuegod63 ~]# mysql -u mk2 -p123456 #Cannot log in

Solution:

mysql> grant all privileges on *.* to 'mk2'@'localhost' identified by '123456' with grant option;

Summary: % refers to any remote host, excluding local addresses and localhost. Grant is effective immediately. No need to execute: mysql> flush privileges; #manual update command

mysql> flush privileges only if mysql related fields are manually modified;

Grant only partial permissions:

mysql> grant select,insert,update,delete,create,drop on aa.* to 'custom'@'localhost' identified by '123456';

Method 2: Modify the permission file in the table directly:

mysql> use mysql;

mysql> insert into user (Host,User,Password) values('localhost','grace','123456');

mysql> select Host,User,Password from user where User="grace";

+-----------+-------+----------+

| Host | User | Password |

+-----------+-------+----------+

| localhost | grace | 123456 |

+-----------+-------+----------+

You can see that the password was stored in plaintext and is now stored encrypted:

mysql> insert into user (Host,User,Password) values('localhost','grace1',password("123456"));

Query OK, 1 row affected, 3 warnings (0.00 sec)

mysql> select Host,User,Password from user where User="grace1";

+-----------+--------+-------------------------------------------+

| Host | User | Password |

+-----------+--------+-------------------------------------------+

| localhost | grace1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+-----------+--------+-------------------------------------------+

1 row in set (0.01 sec)

mysql> flush privileges; #Refresh the privileges table to make the profile effective

or restart mysql database

[root@xuegod63 ~]# service mysqld restart

Testing:

[root@xuegod63 ~]# mysql -u grace -p123456 #Login failed

ERROR 1045 (28000): Access denied for user 'grace'@'localhost' (using password: YES)

[root@xuegod63 ~]# mysql -u grace1 -p123456 #Login successful

Change account password:

Method 1: Use mysqladmin to modify the password

Example 1: When root has no password:

[root@xuegod63 mysql]# mysqladmin -u root -h 192.168.1.63 password '123'

[root@xuegod63 mysql]# mysql -u root -h 192.168.1.63 -p123

Example 2: When root already has a password:

[root@xuegod63 ~]# mysqladmin -u root password '123456' -p123

Method 2: Use set password to change password:

mysql> SET PASSWORD FOR 'grace1'@'localhost' = PASSWORD('123456');

#Note, your mysql library already has a record: grace1'@'localhost

mysql> set password = password ('1234567');

mysql> FLUSH PRIVILEGES;

Reset root password:

[root@xuegod63 mysql]# /etc/init.d/mysqld stop

[root@xuegod63 mysql]# mysqld_safe --skip-grant-tables --skip-networking

Valid only in mysql version 5.1

Open another terminal again: you can enter directly, and then use update to change the password.

[root@xuegod63 aa]# mysql #execute

mysql> update mysql.user set password=password('123456') where host='localhost' and user='root';

[root@xuegod63 aa]# /etc/init.d/mysqld restart

Stopping mysqld: [ OK ]

After reading this article on how to change passwords in mysql 5.1 and remotely log in to mysql database, many readers will definitely want to know more about related content. If you need more industry information, you can pay attention to our industry information column.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report