MySQL 5.1 version change password, and remote login MySQL database

Source: Internet
Author: User

MySQL creates a user and authorizes:

format:grant permission on the database name. Table name to user @ Login host identified by "User password";

grant[British][grɑ:nt] admits; Agree Permission Grant

Example 1: Allow MK users to log on from localhost

Mysql> Grant all on book.* to [e-mail protected] identified by "123456";

#允许访问book数据库下的所有表, only the book table can be accessed, and users of the same server

allow Mk2 users 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 This means that Mk2 users can delegate their privileges to newly created users. In addition, privileges can be added. % refers to any remote host, excluding local address and localhost

flush privileges; Refresh the database

Test:

[Email protected] ~]# mysql-u mk2-h 192.168.1.63-p123456

mysql> #登录正常

But:

[email protected] ~]# mysql-u mk2-h 192.168.1.63-p123456 #不能登录

Workaround:

Mysql> Grant all privileges on * * to ' mk2 ' @ ' 192.168.1.63 ' identified by ' 123456 ' with GRANT option;

[email protected] ~]# mysql-u mk2-p123456 #不能登录

Workaround:

Mysql> Grant all privileges on * * to ' mk2 ' @ ' localhost ' identified by ' 123456 ' with GRANT option;

Summary: % refers to any remote host, excluding the local address and localhost. In addition grant is immediately effective. No execution required:mysql> flush privileges; #手动更新命令

only if you manually modify the MySQL-related fields will you need to perform mysql> flush privileges;

Only partial permissions are authorized:

mysql> Grant Select,insert,update,delete,c Reate,drop on aa.* to ' custom ' @ ' localhost ' identified by ' 123456 ';

Method Two: directly modify the permissions 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 in clear 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; #刷新权限表 to make the configuration file effective

or restart the MySQL database

[Email protected] ~]# service mysqld restart

Test:

[email protected] ~]# mysql-u grace-p123456 #登录不成功

ERROR 1045 (28000): Access denied for user ' grace ' @ ' localhost ' (using Password:yes)

[email protected] ~]# mysql-u grace1-p123456 #登录成功

To modify your account password:

method One: Use mysqladmin to modify the password

Example 1: When Root does not have a password:

[Email protected] mysql]# mysqladmin-u root-h 192.168.1.63 password ' 123 '

[Email protected] mysql]# mysql-u root-h 192.168.1.63-p123

Example 2: When Root already has a password:

[Email protected] ~]# mysqladmin-u root password ' 123456 '-p123

method Two: Use set Password to modify the password:

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

#注, you already have a record in your MySQL library: grace1 ' @ ' localhost

mysql> Set Password = password (' 1234567 ');

mysql> FLUSH privileges;

Reset Root password:

[[email protected] mysql]#/etc/init.d/mysqld stop

[email protected] mysql]# Mysqld_safe --skip-grant-tables --skip-networking

only in mysql5.1 Version valid

re-open again . One terminal: You can go in directly and then use Update to change the password.

[[email protected] aa]# MySQL #执行

mysql> Update Mysql.user Set Password=password (' 123456 ') where host= ' localhost ' and user= ' root ';

[email protected] aa]#/etc/init.d/mysqld Restart

Stopping mysqld: [OK]


MySQL 5.1 version change password, and remote login MySQL database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.