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

17 excellent web designs carefully crafted by startups

Startups often bring us surprises with their unco...

VSCode+CMake+Clang+GCC environment construction tutorial under win10

I plan to use C/C++ to implement basic data struc...

Build a Docker image using Dockerfile

Table of contents Build a Docker image using Dock...

How to configure Jupyter notebook in Docker container

Jupyter notebook is configured under the docker c...

How to handle concurrent updates of MySQL data

Will UPDATE lock? Will the SQL statement be locke...

Detailed explanation of MySQL slow log query

Slow log query function The main function of slow...

A brief discussion on how to write beautiful conditional expressions in JS

Table of contents Multiple conditional statements...

Vue virtual Dom to real Dom conversion

There is another tree structure Javascript object...

VMware and CentOS system installation method to reset the root password

Today's Tasks 1. Choice of Linux distribution...

How to debug loader plugin in webpack project

Recently, when I was learning how to use webpack,...

How to configure the My.ini file when installing MySQL5.6.17 database

I recently used the MySql database when developin...

JS Easy to understand Function and Constructor

Table of contents 1. Overview 1.1 Creating a func...

How to query date and time in mysql

Preface: In project development, some business ta...