How to set up and change passwords for MySQL admin users

Source: Internet
Author: User

1. How to set the password for the administrator root user

[Email protected] ~]# mysqladmin-uroot password ' 12345678 ' #为没有密码的用户设置密码 [[email protected] ~]# mysqladmin-uroot passwo Rd ' 12345678 '-s/data/3306/mysql.sock #适合多实例mysql

2. Change Password method One: Shell command-line modification

[Email protected] ~]# mysqladmin-uroot-p123456 password ' 12345678 ' [[email protected] ~]# mysqladmin-uroot-p123456 pas Sword ' 12345678 '-s/data/3306/mysql.sock

3. How to change the password two: The SQL Statement update modified (suitable for password loss after starting the database with the--skip-grant-tables parameter after the password change)

mysql> desc mysql.user;   #查看user表结构, find the password field +------------------------+------------- ----------------------+------+-----+---------+-------+| field                   | Type                                | null | key | default | extra  |+------------------------+-----------------------------------+------+-----+---------+-------+|  host                    | char (             )              | no   |  pri |         |       | |  User                    | char (            )               | NO    | PRI |         |        | |  password               |  char ()                            | NO   |      |         |        | ... #此处省略39行 ... Mysql> select user,host,password from mysql.user;   #可以看到, the user password stored in MySQL is encrypted +--------+-----------+--------------- ----------------------------+| user   | host      |  password                                   |+ --------+-----------+-------------------------------------------+| system | localhost |  *e1cc002c309f98deee357e8b53be83c4e2c451a0 |+--------+-----------+---------------------------------- ---------+1 row in set  (0.00 sec) mysql> update mysql.user set  Password=password (12345678)  where user= ' system '  and host= ' localhost ';   # Use the password function to encrypt the new password, otherwise the modified password is clear text, unable to log in query ok, 1 row affected  (0.15 sec) rows  Matched: 1 &nbsP changed: 1  warnings: 0mysql> flush privileges;   #需要刷新之后才生效, Otherwise it only exists in memory and cannot be written to the data file query ok, 0 rows affected  (0.00 sec)

4. How to change the password three: With SQL statement set modification (the most convenient, but only the current logged on user's password can be modified)

mysql> SET Password=password (' 12345678 '); #这里必须加引号Query OK, 0 Row Affected (0.00 sec) mysql> FLUSH privileges; Query OK, 0 rows Affected (0.00 sec)


How to set up and change passwords for MySQL admin users

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.