Get the App
SLTechnology News&Howtos  ›  Database  › 

Linux changes the password of mysql

Shulou Source: shulou.com Published: 2022-06-01 09:43:12 10月03日 Update

I installed mysql-server in the centos6.8 container of docker, but I was not prompted to set the password during the installation, but after installation, I used root users to enter without entering the password, so I need to change the password of mysql.

Mysql-uroot-pmysql > update user set password=PASSWORD ('you password') where user='root'; for example: mysql > update user set password=PASSWORD (' admin123') where user='root';mysql > flush privileges;mysql > exit

After restarting mysql, you can log in with the password you just set.

If mysql sets the password but forgets it, you need to reset the password like this

First find the my.conf file of mysql, and add skip-grant-tables under [mysqld]. Skip password verification, and you can log in to mysql without a password.

Vim / etc/my.conf [mysqld] datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0skip-grant-tables # Skip password authentication [mysqld_safe] log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

After restarting, you can log in to mysql without a password. After entering, set the password of root according to the above method. After setting it, delete or comment out the fields in the my.conf file that skip password verification, and then restart to log in with the password you just set.

Tags: Password login authentication done file for this field container situation method time comment user face Zhongan prompt input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia MySQL macOS Huawei