Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's default password in docker container mysql-server when you don't set one?

Tags:

docker

mysql

I am try to run a mysql container and connect with mysql client then:

I've used following commands:

docker run --name=mysql -d mysql/mysql-server:latest
docker exec -it mysql mysql -uroot -p

According to tutorial, the last command allow me configure database password but When I introduce the first password it fails...

enter image description here

The first password was root and I get an unusual error, then I try with admin, admin an even my linux user password but They don't work...

I would like to know what's the error?

like image 246
Cesar Miguel Avatar asked May 28 '20 19:05

Cesar Miguel


People also ask

How do I find my Docker MySQL password?

Logging into the MySQL Server You will be prompted for the root user's password. Use the password revealed by the docker logs mysql01 command. Once within the MySQL server, you can then change the password with the command: ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

What is the default root password for MySQL?

The default user for MySQL is root and by default it has no password. If you set a password for MySQL and you can't recall it, you can always reset it and choose another one.

What is the default root password in Docker?

By default, “0” denotes root user. You can also choose to specify, simply as “root”. I always find the above command handy in most situations to execute on a running container.

How do I connect to a MySQL Docker container?

Here are the steps you can follow to install the Dockerhub MySQL Container: Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.


2 Answers

There are couple of ways to see the password. First Approach - Don't Run container in daemon mode

Check the below command

docker run --name=mysql mysql/mysql-server:latest

and this will print the password in the terminal as look at the below logs

2020-05-28T23:41:01.418347Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
2020-05-28T23:41:01.666070Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-05-28T23:41:01.714420Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20'  socket: '/var/lib/mysql/mysql.sock'  port: 0  MySQL Community 
Server - GPL.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Entrypoint] GENERATED ROOT PASSWORD: PopiKQIjAS#OGj3x]yJOBLEn80p
[Entrypoint] ignoring /docker-entrypoint-initdb.d/*
2020-05-28T23:41:06.208480Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.20).
2020-05-28T23:41:07.861667Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.
[Entrypoint] Server shut down
[Entrypoint] Setting root user as expired. Password will need to be changed before database can be used.
[Entrypoint] MySQL init process done. Ready for start up.
[Entrypoint] Starting MySQL 8.0.20-1.1.16
2020-05-28T23:41:08.534785Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 1
2020-05-28T23:41:08.549216Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-05-28T23:41:09.135591Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-05-28T23:41:09.369412Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2020-05-28T23:41:09.448584Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-05-28T23:41:09.500464Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Communi
ty Server - GPL.

Second Approach - Run container in daemon mode & fetch the password from logs Check the below command to run the container

docker run -d --name=mysql mysql/mysql-server:latest

and then run the below command to fetch the password

docker logs mysql 2>&1 | grep GENERATED

Output of above command is:

[Entrypoint] GENERATED ROOT PASSWORD: PopiKQIjAS#OGj3x]yJOBLEn80p

Once you have the password by one of the above-mentioned methods, you can then login with the below command using that password

docker exec -it mysql mysql -uroot -p

When asked, enter the generated root password (see the instructions above on how to find it). Because the MYSQL_ONETIME_PASSWORD option is true by default, after you have connected a mysql client to the server, you must reset the server root password by issuing this statement:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

Substitute password with the password of your choice. Once the password is reset, the server is ready for use.

Ref: https://hub.docker.com/r/mysql/mysql-server/

like image 168
nischay goyal Avatar answered Oct 09 '22 09:10

nischay goyal


docker inspect <container_name_here> command output shows root password among other params

like image 29
atlascoder Avatar answered Oct 09 '22 11:10

atlascoder