2018-03-28 set up and modify MySQL user password learning notes

Source: Internet
Author: User

Exit MySQL Method

Quit or exit

Set up and modify Mysqlroot user password

After installing MySQL, the default administrator root password is empty, which is not secure, you need to set a password, after installing MySQL Single instance, there are some initial optimization of the security measures:

    1. Password was set for root
    2. Delete the user account in the useless MySQL library.
    3. Delete the test database that exists by default

In addition to the above methods, for MySQL database user processing, we also have more stringent practices as follows:

    1. Add system and promote to Super Administrator, that is, the user with root equivalent, but the name is different.

      Mysql>grant all Privileges "to [e - mail protected] ' localhost ' identified by ' 123456 ' with GRANT option;
      Query OK, 0 rows Affected (0.00 sec)

    2. Delete all users in MySQL, including root super user.

      Mysql>delete from Mysql.user;
      Query OK, 2 rows Affected (0.00 sec)

To set the password method for the administrator root user
    • mysqladmin-u root password ' 123456 ' <---user password command without password
    • Mysqladmin-u root-p ' 123456 ' password ' dc123456 '-s/data/3306/mysql.sock <----suitable for multi-instance mode

        以上的命令是在linux命令行,不是MySQL命令行
Modify Administrator root password method one: command-line Modification method
    • Mysqladmin-u root-p ' 123456 ' password ' dc123456 '
    • Mysqladmin-u root-p ' 123456 ' password ' dc123456 '-s/data/3306/mysql.sock <----suitable for multi-instance mode
Modify Administrator root password method two: SQL statement modification method
    • Mysql>update mysql.user SET Password=password ("dc123456") WHERE user= ' root ';
    • Flush privileges; <----Refresh configuration file
        提示:此法适合密码丢失后通过--skip-grant-tables参数启动数据库后修改密码。  重要提示:1、必须指定条件2、必须指定password()函数来加密更改密码,否则无效。
Modify Administrator root Password method three

After the MySQL installation is complete, the root default password is empty and the root password needs to be changed immediately:

    • Mysql>set Password=password (' 123456 ');
        提示:此法不适合--skip-grant-tables方式修改密码。

After modifying the password operation, flush privileges should be performed;

Recover lost MySQL root user password start modify missing MySQL Single instance root password method
    1. Stop MySQL First
      • [[email protected] ~]#/etc/init.d/mysqld stop
    2. Use--skip-grant-tables to log in to MySQL, ignoring authorization login verification.
      • [Email protected] ~]# mysqld_safe--skip-grant-tables--user=mysql &
      • [[email protected] ~]# MySQL <----login time password
    3. Use update to modify the root password, you cannot use Mysqladmin password to modify, because the original password needs to be provided.
      • Mysql>update Mysql.user Set Password=password ("dc123456") where user= ' root ' and host= ' localhost '; <----Change Password
      • Flush privileges; <----Refresh Permissions
      • Mysql>quit
      • mysqladmin-uroot-pdc123456 Shutdown <----close MSYQL
      • /etc/init.d/mysqld Start <----must be restarted
      • mysql-uroot-pdc123456 <-----New Password Login
    提示:在启动时加--skip-grant-tables参数,表示忽略授权表验证。
Multi-instance MySQL startup modify lost root password method
    1. Turn off MySQL
    2. Add--skip-grant-tables parameter at startup
      • Mysqld_safe--defaults-file=/data/3306/my.cnf--skip-grant-table &
      • Mysql-uroot-p-s/data/3306/mysql.sock <----login time password
    3. Modify Password method
      • Mysql>update Mysql.user Set Password=password ("dc123456") where user= ' root ' and host= ' localhost '; <----Change Password
        • Flush privileges; <----Refresh Permissions
        • Mysql>quit
        • [[email protected] ~]# mysqladmin-uroot-pdc123456 shutdown <----close MSYQL
        • [[email protected] ~]#/ETC/INIT.D/MYSQLD Start <----must be rebooted to start normally.
        • [[email protected] ~]# mysql-uroot-pdc123456 <-----new Password Login

2018-03-28 set up and modify MySQL user password learning notes

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.