show databases mysql docker 1

show databases mysql docker

First, go inside docker container, run below command
docker exec -it mysql_container_name mysql -uroot -p
where “root” is the username for MySQL database. After running above command it will ask you a password.

Then Select Database, run below command
USE Name-Of-The-Database

get the list of all tables.
show tables;

Here is what the above code is Doing:
1. We are creating a connection to the database using the connect() function.
2. We are creating a cursor object using the cursor() function.
3. We are executing the query using the execute() function.
4. We are fetching all the rows using the fetchall() function.
5. We are printing the rows.
6. We are closing the connection using the close() function.

Similar Posts