Common mysql commands-User Password Modification

Source: Internet
Author: User
Tags mysql commands

Common mysql commands-User Password Modification

-- Create user 'user1' @ 'localhost' identified by 'pass1'; grant select, INSERT, UPDATE, delete on *. * TO 'user1' @ 'localhost'; grant all on *. * TO 'user1' @ 'localhost ';

 

1. root Password Modification Method 1: Use the mysqladmin command
-- Applies to remembering the old root password and modifying the root password Syntax: mysqladmin-u username-p old password new password example: # mysqladmin-u root-proot password mysql -- Note: if the old password is entered incorrectly, the following error will be reported # mysqladmin-u root-proot1 password mysqlmysqladmin: connect to server at 'localhost' failederror: 'Access denied for user' root' @ 'localhost' (using password: YES )'

 

Method 2: directly update the password field of the user table
-- This method is used to reset the root password when you forget the root password. Step 1: Modify the MySQL Logon Settings # vi/etc/my. cnf -- windows system is my. INI file -- Add the following sentence to the [mysqld] section: skip-grant-tables. If the [mysqld] field is not found, you can manually add [mysqld] datadir =/var/lib/mysqlsocket =/var/lib/mysql. sockskip-name-resolveskip-grant-tablesStep 2: restart mysql [root @ gc ~] # Service mysql restartShutting down MySQL .. [OK] Starting MySQL... [OK] Step 3: log on to and modify the MySQL root Password. At this time, you can directly use mysql to access the database without a password. [root @ gc ~] # MysqlWelcome to the MySQL monitor. commands end with; or \ g. your MySQL connection id is 2 Server version: 5.5.24 MySQL Community Server (GPL) Copyright (c) 2000,201 1, Oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners. type 'help; 'or' \ H' for help. type '\ C' to clear The current input statement. mysql> use mysql; Database changedmysql> update user set password = password ('new _ password') where user = 'root'; Query OK, 5 rows affected (0.00 sec) rows matched: 5 Changed: 5 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) -- Note: If Step 1 is not performed, the following error [root @ gc ~] will be reported when you log on with mysql directly. # MysqlERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO) Step 4: modify the MySQL Logon Settings and then delete/etc/my. skip-grant-tablesStep 5 in the cnf file: restart mysql [root @ gc ~] # Service mysql restartShutting down MySQL... [OK] Starting MySQL... [OK]

 

2. Change the password of other mysql users. You can also use the following methods for common users.
-- Use the mysqladmin Command [root @ njdyw ~] # Mysqladmin-u user1-ppass1 password pass2 -- directly modify the database table [root @ njdyw ~] # Mysql-u user1-ppass1-Dmysqlmysql> update user set password = password ('pass2') where user = 'user1'; mysql> flush privileges;

 

 

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.