Access denied for user 'root'#'localhost' in the mysql docker - mysql

Running a docker mysql container in the following command
docker run -it --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
then docker creates a running mysql container with logs as
2020-07-23 09:39:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-07-23T09:39:20.408751Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-23T09:39:20.408909Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 42
2020-07-23T09:39:20.424771Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-23T09:39:22.342488Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-23T09:39:26.473394Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-07-23 09:39:35+00:00 [Note] [Entrypoint]: Database files initialized
2020-07-23 09:39:35+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/da5f3f1ae045.err
mysqld is running as pid 91
2020-07-23 09:39:37+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' 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.
2020-07-23 09:39:56+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-07-23 09:39:59+00:00 [Note] [Entrypoint]: Temporary server stopped
2020-07-23 09:39:59+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2020-07-23T09:39:59.908211Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-23T09:39:59.910343Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
2020-07-23T09:39:59.945124Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-23T09:40:00.579927Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-23T09:40:00.969050Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2020-07-23T09:40:01.137873Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-07-23T09:40:01.138424Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-07-23T09:40:01.145079Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-07-23T09:40:01.233430Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
Trying to access the container with
mysql -h localhost -u root -p
it asks for the password, using 123456 as the password fails; using empty password also fails.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)

docker exec -it mysql mysql -uroot -p, then a prompt is out to input the password with 123456, then It can successfully get access to the mysql command line. however why I can't use tableplus
From the comment above it's verified that you are able to access the mysql server inside the container, so the issue with tableplus not the container root password.
Just publish the port and it should work,
docker run -it -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
Also, it seems like tableplus connecting with host MySQL instead of container one as container did not publish the port in your case so it trying to connect somewhere else.

It might be that this MySQL installation uses authentication mechanisms of the operating system. Instead of the root passowrd.
To test if that's the case, execute the following command:
sudo mysql -u root
It will ask you for your operating system privileged password, not the MySQL root password (which might be unset).
After you get in, you can add new users, as usual and as described in MySQL manual and tutorials.
Also, you might want try the instructions mentioned here:
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
See section "B.4.3.2.3 Resetting the Root Password: Generic Instructions".
Quoting it below (and cleaned up a bit), in case if the website is not reachable:
Stop the MySQL server if necessary, then restart it with the
--skip-grant-tables option (see How to start MySQL with --skip-grant-tables? for some ways how to do it)
Connect to the MySQL server using the mysql client; no password is
necessary because the server was started with --skip-grant-tables:
shell> mysql
In the mysql client, tell the server to reload the grant
tables so that account-management statements work:
mysql> FLUSH PRIVILEGES;
Then change the 'root'#'localhost' account
password. Replace the password with the password that you want to use.
To change the password for a root account with a different host name
part, modify the instructions to use that host name.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
You
should now be able to connect to the MySQL server as root using the
new password. Stop the server and restart it normally (without the
--skip-grant-tables option).

I had the same issue and i fixed it replacing localhost with the private ip:
mysql -u root -p -h 192.168.10.4

Related

MySQL Error 1045: Access denied for user 'root'#'localhost' (using password: YES)

I install MySQL Workbench 8.0.22 on windows. But I am not able to make a successful connection.What should I do to correct this?Although I enter the correct password, I got Access denied for user 'root'#'localhost' (using password: YES) and cannot make db conection. Please help me. What I have done so far is,
I delete MySQL file in this path:
%AppData%\MySQL
Then I followed these steps for resetting root password:
Resetting the Root Password: Windows Systems
After I run this command
mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file=C:\\mysql-init.txt --console
on CMD (running as administrator) I got:
2021-07-23T09:36:09.763074Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2021-07-23T09:36:09.764268Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 8892
2021-07-23T09:36:09.765503Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-07-23T09:36:09.765528Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8_unicode_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2021-07-23T09:36:09.835697Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-07-23T09:36:12.223043Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-07-23T09:36:13.527018Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2021-07-23T09:36:13.756941Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2021-07-23T09:36:13.773592Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
2021-07-23T09:36:14.104612Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-07-23T09:36:14.106154Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-07-23T09:36:14.174295Z 0 [Warning] [MY-010319] [Server] Found invalid password for user: 'root#localhost'; Ignoring user
2021-07-23T09:36:14.276943Z 7 [Warning] [MY-010319] [Server] Found invalid password for user: 'root#localhost'; Ignoring user
2021-07-23T09:36:14.278797Z 7 [ERROR] [MY-000061] [Server] 1396 Operation ALTER USER failed for 'root'#'localhost'.
2021-07-23T09:36:14.284169Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: '8.0.22' socket: '' port: 3306 MySQL Community Server - GPL.
I tried to connect db on MySQL Workbench 8.0:
When I double click on my database connection:
Then I deleted all connections,
and tried to create a new connection and click on the "Test Connection" button:
I tried on MySQL Shell:
When I run this command then enter password for root user:
\connect root#localhost
Creating a session to 'root#localhost'<br />
Please provide the password for 'root#localhost': **** <br />
MySQL Error 1045: Access denied for user 'root'#'localhost' (using password: YES)
I tried on CMD:
mysqld --skip-grant-tables
2021-07-23T09:46:44.161756Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 14700
2021-07-23T09:46:44.168273Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2021-07-23T09:46:44.168472Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2021-07-23T09:46:44.172258Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)
2021-07-23T09:46:44.173769Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-07-23T09:46:44.173965Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22) MySQL Community Server - GPL.
mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Then I open CMD terminal, run as administrator, enter the command below to observe my MySQL port status (3306):
netstat -a -b
TCP [::]:3306 DESKTOP-MY:0 LISTENING
[mysqld.exe]

Wamp MYSQL can't start

I have a problem with my WAMPServer since few weeks.
MySQL service can't start and I don't have the solution...
I've tried to uninstall and install Wamp and change the MySQL who is not used, but he can't start, why ?
Error is :
2021-05-07T09:45:13.549741Z 0 [System] [MY-010116] [Server] c:\wamp64\bin\mysql\mysql8.0.21\bin\mysqld.exe (mysqld 8.0.21) starting as process 22580
2021-05-07T09:45:13.731100Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-05-07T09:45:14.624458Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-05-07T09:45:14.962879Z 0 [ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: An attempt was made to access a socket in a way forbidden by its access permissions.
2021-05-07T09:45:14.963609Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3306 ?
2021-05-07T09:45:14.964258Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-05-07T09:45:16.076956Z 0 [System] [MY-010910] [Server] c:\wamp64\bin\mysql\mysql8.0.21\bin\mysqld.exe: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.
Thanks in advance.
Seems both port 3306(MySQL) and 3307(mariaDB) are in use by some other process.
Start a command window using "Run as Administrator" then do
netstat -anob | findstr "3306"
that should show you what is using port 3306, the output is like this
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 19768
TCP [::]:3306 [::]:0 LISTENING 19768
The last number 19768 is a PID and you then do the following to find the program running on that PID
tasklist|findstr "19768"
Of course the PID you will see will not be the same number as mine, once you know what program is using port 3306 you can decide what to do about it!
If you are not sure comment under here and we can work it out between us
Final Suggestion
The only "trick" that comes to mind would be to perform a network "clean-up".
In a "as administrator" command window, type the following commands:
netsh winsock reset
netsh winsock reset catalog
netsh int ip reset reset.log
netsh int ipv4 reset reset.log
netsh int ipv6 reset reset.log
ipconfig /flushdns
This resets the IP configuration.
At the end, the system must be restarted.

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

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...
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?
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/
docker inspect <container_name_here> command output shows root password among other params
When starting a mysql container for the first time, there is no default password. The password you set while running the container is the default password that will be assigned to your root.
Starting a MySQL instance is simple:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
where some-mysql is the name you want to assign to your container, my-secret-pw is the password to be set for the MySQL root user and tag is the tag specifying the MySQL version you want. See the list above for relevant tags.
Following the documentation in: https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html
You get the password with command:
docker logs mysql 2>&1 | grep GENERATED
Example output:
GENERATED ROOT PASSWORD: Axegh3kAJyDLaRuBemecis&EShOs
There is no default password, try login in using:
sudo docker exec -it mysql mysql -u root

I am getting wordpress mysql connection error using docker

I created two docker containers using the commands below.
docker pull wordpress
docker pull mysql
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d mysql
docker run --name wordpress_website --link wordpress_database:mysql -p 8080:80 -d wordpress
When I looked at the later logs, I encountered an error. Logs are below.
How do I prevent these errors?
docker logs wordpress_website
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
MySQL Connection Error: (2054) The server requested authentication method unknown to the client
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
WARNING: unable to establish a database connection to 'mysql'
continuing anyways (which might have unexpected results)
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Wed Apr 15 12:09:06.057462 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.16 configured -- resuming normal operations
[Wed Apr 15 12:09:06.057505 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
docker logs wordpress_database
2020-04-15 12:07:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-04-15T12:07:20.102858Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:20.102959Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 43
2020-04-15T12:07:23.537919Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Database files initialized
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Starting temporary server
2020-04-15T12:07:27.774674Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:27.774765Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 93
2020-04-15T12:07:28.389657Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:28.397651Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:28.421413Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-04-15 12:07:28+00:00 [Note] [Entrypoint]: Temporary server started.
2020-04-15T12:07:28.457791Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' 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.
2020-04-15 12:07:30+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-04-15T12:07:30.812504Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
2020-04-15T12:07:32.529079Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: Temporary server stopped
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2020-04-15T12:07:33.133835Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:33.133938Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
2020-04-15T12:07:33.647310Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:33.652627Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:33.673452Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2020-04-15T12:07:33.812073Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
localhost:8080
Error establishing a database connection
You need to publish ports to the host interface for MySQL container. Use this command to start the MySQL docker container:
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mysql
Read this for more details regarding publishing ports in a docker container.

MySQL Docker Image: initialized with env variable of K8S Secret

When i tried to deploy with K8S using env variable for Root Password (MYSQL_ROOT_PASSWORD , a variable used in docker-entrypoint.sh) such as
kind: Deployment
#omitted...
spec:
containers:
#omitted...
env:
- name: MYSQL_ROOT_PASSWORD
value: my-secret-passw
it seems that the deployment with kubectl apply -k is working. Of course, this insecure deployment. MySql initialization works and everything is as expected.
So i tried to create a secret and retrieving the value from that secret, such that
kind: Deployment
#omitted...
spec:
containers:
#omitted...
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
key: MYSQL_ROOT_PASSWORD
name: mysql-root-password
mysql initialization is not working. And i have no idea what the heck is going wrong. The kubectl logs or stdout from the container is the following (bear in mind that using literal root pass didn't return result like this):
[MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' 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.
[Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/sql-script.sql
mysql: [ERROR] unknown option '-- "'.
When checking the docker image source code, it seems there is no string about "unknown option" (see here the github and i am using mysql 8.0. It seems it's coming out of mysql itself.
So why is it that when using literal value on k8S env variable (which is not safe!) working but not with reading from secret?
Seems like version 8.0 is broken or missing something because it cannot see the password.
I'm not an expert in this field so maybe someone else can add some more details.
2020-02-07T16:09:06.648827Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-02-07T16:09:06.649084Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 44
2020-02-07T16:09:10.821145Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-02-07 16:09:14+00:00 [Note] [Entrypoint]: Database files initialized
2020-02-07 16:09:14+00:00 [Note] [Entrypoint]: Starting temporary server
2020-02-07T16:09:14.823453Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-02-07T16:09:14.823582Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 94
2020-02-07T16:09:15.631008Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-02-07T16:09:15.635649Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-02-07T16:09:15.655790Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-02-07 16:09:15+00:00 [Note] [Entrypoint]: Temporary server started.
2020-02-07T16:09:15.740600Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' 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.
2020-02-07 16:09:19+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-02-07T16:09:19.476870Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
I've tested the image 5.6 from official mysql repository and it's seems to work perfectly fine.
I've run whole MySQL + WordPress deployment using the Tutorial on kubernetes.io which I do recommend.
I've created the secret manually, using:
kubectl create secret generic mysql-pass --from-literal=password=test
Looks like there is an issue open for problem similar to this "Unable to start server" on Amazon Linux AMI (works with 5.7) #628.
After sometime, i realized that the problem is not with the Secret of K8S. I accidentally changed my password into string of chars without Special characters, and that solved it! From the post, you see that the character -- was read as an input of the next process (dang it, i am giving away my pass! nah, changed it already).
So anyone of you with the same problem (with mysql), please consider choosing a secret with no-special-characters password. Long password with combination of numbers/case-sensitive could be strong enough, especially if you paper and pencil!