当前位置:网站首页>Change password of MySQL version 5.7 and 8.0
Change password of MySQL version 5.7 and 8.0
2022-07-01 09:45:00 【Little black notes】
Catalog
5.7 edition (centos7 Li test )
1、 Forget the password , Skip detection
The first one is , use docker Installed , Into the container /etc/mysql And externally mounted direct modification files
[[email protected] mysqlconfig]# docker exec -it 97ca731b5ff4 /bin/bash
[email protected]:/# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[email protected]:/# cd /etc/mysql/conf.d
[email protected]:/# vi docker.cnf
[mysqld]
skip-host-cache
skip-name-resolve
skip-grant-tables # Add this line
If there is no... In the container vi Instructions , Also unwilling to install , You can also modify it from the attached path , I use it here. docker-compose Installed
[[email protected] ~]# cat docker-compose.yml
version: "2.1"
services:
mysql:
image: mysql:5.7.20
restart: unless-stopped
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
volumes:
- /data/docker/mysql/mysql:/var/lib/mysql
- /data/docker/mysql/mysqlconfig:/etc/mysql
[[email protected] ~]#
[[email protected] conf.d]# pwd
/data/docker/mysql/mysqlconfig/conf.d
[[email protected] conf.d]# vi docker.cnf
[mysqld]
skip-host-cache
skip-name-resolve
skip-grant-tables # Add this line
If there's nothing here , Just use it again docker run Run a test mysql, And then use docker cp To copy the inside of the container /etc/mysql Catalog , Be careful not to mount the directory , Or you'll play for nothing
Example :
Pay attention to the whole catalogue here , During my experiment , In case of incomplete documents , Containers don't work
[[email protected] tmp]# docker cp 97ca731b5ff4:/etc/mysql .
Here is the official operating environment mysql Container mount Directory , It's mentioned above
[[email protected] tmp]# cp mysql/* /data/docker/mysql/mysqlconfig/
The second kind , Direct will mysql Installed on the host , I didn't do a test , Online modification /etc/mysql/my.cnf file , It also increases skip-grant-tables
2、 Empty password
# Write the new password directly , Neither old nor new passwords can log in
[email protected]:/# mysql -uroot -p
Enter password:
# The display content is omitted
mysql> use mysql
mysql> update user set authentication_string='' where user = 'root';
3、 Write new password
mysql> use mysql
mysql> update user set authentication_string=password('123456') where user='root';
# It's also OK to write in the following way , It's convenient
mysql> update mysql.user set authentication_string=password('123456') where user='root';
4、 Refresh the permissions
mysql> flush privileges;
5、 give root All permissions of all databases of the user
mysql> grant all privileges on *.* to [email protected]'%' identified by '123456';
mysql> flush privileges;
8.0 edition (Ubuntu 20.04.3 Made in , Someone else's machine , It's not easy to do too many experiments )
1、 By default, the account secret is automatically generated
During installation , Directly installed in the host , The automatically generated account and password used , So I don't know root password
Automatically generated account and password
account number :debian-sys-maint
password :BcJnVUVx3JlY0Vq5
Because of the password , So it is reset after logging in directly root password , There is no such step as setting password free login
2、 Empty password ( And 5.7 There's a difference )
[email protected]:~$ mysql -udebian-sys-maint -pBcJnVUVx3JlY0Vq5
# At this moment , Confused to change the password encryption method , It doesn't matter if there's no impact
mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
mysql> select user ,plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | mysql_native_password |
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
| zsw | caching_sha2_password |
+------------------+-----------------------+
7 rows in set (0.00 sec)
mysql> use mysql
mysql> update user set authentication_string='' where user='root';
# I saw it on the Internet ,authentication_string='' There is none here password Field , Because the contents in the table below are mysql 8.0 Li changed
mysql> show fields from user; # Or use describe user;
# The content here is omitted
| plugin | char(64) | NO | | caching_sha2_password | |
| authentication_string | text | YES | | NULL | |
# The content here is omitted
3、 Write new password
mysql> use mysql
mysql> update user set authentication_string='123456#Abc' where user='root';
4、 Refresh the permissions
mysql> flush privileges;
5、 give root All permissions of all databases of the user
mysql> grant all privileges on *.* to [email protected]'%' identified by '123456#Abc';
mysql> flush privileges;
Add :
// Delete user .
mysql>use mysql;
mysql>delete from user where User="test" and Host="localhost";
mysql>flush privileges;
// Delete user's database
mysql>drop database test;
边栏推荐
- JS variable lifting
- Live broadcast management project
- 新数据库时代,不要只学 Oracle、MySQL
- Get the list of a column in phpexcel get the letters of a column
- JS原型链
- SQL learning notes (04) - data update and query operations
- 年薪100万,在北上广深买的起房子吗?
- ES6 decoupling top-level objects from windows
- CSDN一站式云服务开放内测,诚邀新老用户来抢鲜
- Dspic30f6014a LCD block display
猜你喜欢

全球基金和资管的股票建仓率达到15年内新低

我喜欢两个男人。。。

Network counting 01 physical layer

Introduction to expressions and operators in C language

HMS core audio editing service 3D audio technology helps create an immersive auditory feast

Initial experience of Flink, a mainstream real-time stream processing computing framework

ESP8266 FreeRTOS开发环境搭建

Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture

Hololens2 development -6-eyetracking and speech recognition

这样理解mmap,挺有意思!
随机推荐
MT7628K eCos开发入门
ESP8266 FreeRTOS开发环境搭建
Packetdrill script analysis guide
Drive away bad emotions and stop worrying
Hardware midrange project
Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
JS variable lifting
那个程序员,被打了。
Live broadcast management project
Cortex M4 systick details
js变量提升(hoisting)
js作用域链与闭包
Error org apache. catalina. core. StandardContext. FilterStart start filter exception
架构实战营 模块九:设计电商秒杀系统
JS rewrite their own functions
SQL learning notes (04) - data update and query operations
Differences between JS valueof and toString
[untitled]
123. how to stop a thread?
SQL learning notes (02) - database table operation