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