How to modify the password of MySQL 5.1 and remotely log in to the MySQL database

How to modify the password of MySQL 5.1 and remotely log in to the MySQL database

Create a mysql user and authorize:

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

grant[英][grɑ:nt] admit; agree; allow; grant;

Example 1: Allow the mk user to log in from localhost

mysql> grant all on book.* to mk1@localhost identified by "123456";
 #Allow access to all tables under the book database. Only book tables can be accessed, and users on the same server

Allow the mk2 user to connect to the mysql server from any remote host:

mysql> grant all privileges on *.* to mk2@'%' identified by '123456' with grant option;
# with grant option means that the mk2 user can delegate his own permissions to the newly created user. In addition, you can add or not add privileges. % refers to any remote host, excluding local addresses and localhost
Flush privileges; Refresh the database

test:

[root@xuegod64 ~]# mysql -u mk2 -h 192.168.1.63 -p123456
mysql> #Login is normal

but:

[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;

To summarize: % refers to any remote host, excluding the local address and localhost. In addition, the grant takes effect immediately. No need to execute: mysql> flush privileges; #Manual update command

Only when you manually modify the MySQL related fields, you need to execute mysql> flush privileges;

Authorize only some permissions:

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

Method 2: Directly modify the permission file in the table:

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 is stored in plain text and is now stored in encrypted form:

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 privilege table to make the configuration file effective

Or restart the mysql database

[root@xuegod63 ~]# service mysqld restart

test:

[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

To change your account password:

Method 1: Use mysqladmin to change 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 the password:

mysql> SET PASSWORD FOR 'grace1'@'localhost' = PASSWORD('123456');
#Note, your MySQL database 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

Only valid in MySQL 5.1

Open a new terminal: You can log in 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 ]

The above is the method of changing the password and remotely logging into the MySQL database in MySQL 5.1 version introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to install the green version of MySQL Community Server 5.7.16 and implement remote login
  • Linux platform mysql enable remote login
  • mysql modify password and set to allow remote login
  • How to set up remote login to Mysql database
  • Solution to mysql remote login error
  • How to implement remote login in MySQL
  • About MYSQL remote login authorization method command
  • Tutorial on installing and configuring remote login to MySQL under Ubuntu

<<:  A record of the pitfalls of the WeChat applet component life cycle

>>:  Some functions of using tcpdump to capture packets in the Linux command line

Recommend

Solve the problem of OpenLayers 3 loading vector map source

1. Vector Map Vector graphics use straight lines ...

Basic knowledge: What does http mean before a website address?

What is HTTP? When we want to browse a website, w...

Hexadecimal color codes (full)

Red and pink, and their hexadecimal codes. #99003...

A brief analysis of the configuration items of the Angular CLI release path

Preface Project release always requires packaging...

JavaScript to implement login slider verification

This article example shares the specific code of ...

Detailed tutorial on uploading and configuring jdk and tomcat on linux

Preparation 1. Start the virtual machine 2. git t...

Typical cases of MySQL index failure

Table of contents Typical Cases Appendix: Common ...

Talk about how to identify HTML escape characters through code

Occasionally you'll see characters such as &#...

How to use JS code compiler Monaco

Preface My needs are syntax highlighting, functio...

In-depth explanation of the style feature in Vue3 single-file components

Table of contents style scoped style module State...

Specific method to add foreign key constraints in mysql

The operating environment of this tutorial: Windo...

Echarts legend component properties and source code

The legend component is a commonly used component...

Vue realizes the whole process of slider drag verification function

Rendering Define the skeleton, write HTML and CSS...

How to use display:olck/none to create a menu bar

The effect of completing a menu bar through displ...

Detailed explanation of Linux CPU load and CPU utilization

CPU Load and CPU Utilization Both of these can re...