Mysql not starting on docker - mysql

I'm using laravel sail to launch a statamic website on my local machine (macOS). All packages are up-to-date and launch correctly however, the mysql service starts, then fails due to "another process with pid 62 is using unix socket file.".
I'm using the default sail docker-compose file, uneditted. It is working on my other, linux machine correctly with no issues. When visiting localhost, I'm met with "SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known" which makes me think that it is connecting somehow as I would normally expect connection refused?
Here are the docker mysql container logs:
[Entrypoint] MySQL Docker Image 8.0.32-1.2.11-server
[Entrypoint] Starting MySQL 8.0.32-1.2.11-server
2023-01-26T21:17:04.876429Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-01-26T21:17:04.878708Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
2023-01-26T21:17:04.885183Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-26T21:17:05.037353Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-26T21:17:05.189336Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-01-26T21:17:05.189362Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-01-26T21:17:05.189506Z 0 [ERROR] [MY-010259] [Server] Another process with pid 62 is using unix socket file.
2023-01-26T21:17:05.189518Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
2023-01-26T21:17:05.189521Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-01-26T21:17:06.724573Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
Thanks in advance.

I solve mine (WSL2, Docker Desktop) by opening the Docker Desktop GUI, opened the Volumes sidebar. Search for all volume that has "mysql" on their name and delete those volumes. Then run docker compose up again.

Related

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

I used the Digitalocean one-click installation to set up a Ghost instance on my server and I recently noticed that the site is showing a 502 gateway error, when I logged in to check I found that the server is not active.
I get this error and I’m not able to start the MySQL server.
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
I followed this guide here https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-socket-errors-in-mysql
But I found that I don’t even have the /var/run/mysqld/ directory When I try to cd or ls that directory, it shows the directory does not exist.
I guess my own case is different, I browsed around the internet and found this solution that suggested I add
innodb_force_recovery = 6
https://askubuntu.com/questions/1185783/how-fix-permanently-job-for-mysql-service-failed-because-the-control-process-ex
After adding that code, it still does not solve the problem
When I go into the /var/log/mysql/error.log file I get this
2022-08-08T01:40:28.108418Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30-0ubuntu0.20.04.2) (Ubuntu).
2022-08-08T01:40:28.677008Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30-0ubuntu0.20.04.2) starting as process 271100
2022-08-08T01:40:28.688821Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-08T01:40:28.928619Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-08T01:40:29.023994Z 1 [Warning] [MY-011018] [InnoDB] Skip updating information_schema metadata in InnoDB read-only mode.
2022-08-08T01:40:29.229659Z 1 [Warning] [MY-010005] [Server] Skip re-populating collations and character sets tables in InnoDB read-only mode.
2022-08-08T01:40:29.235974Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-08-08T01:40:29.236037Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-08-08T01:40:29.760446Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30-0ubuntu0.20.04.2) (Ubuntu).
Thank you so much for your help!

Unable to start mysql on MacOS

I'm trying to set up MySQL on my MacBook Pro, OS Monterey. When I press "Start MySQL Server" in System Preferences, it turns on, and then back off again. Sometimes it will stay on (after uninstalling, restarting my computer, and reinstalling), however when I try mysql -u root -p in terminal, or logging in on MySQL Workbench with the password I set during install, it says Access Denied. When I try to initialize a database, I get this error:
2022-08-17T13:58:03.594154Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.30-macos12-arm64/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 1279
2022-08-17T13:58:03.596412Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql-8.0.30-macos12-arm64/data/ is case insensitive
2022-08-17T13:58:03.604502Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-17T13:58:03.721094Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-17T13:58:05.536330Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root#localhost: W<dvfErrh0DC
2022-08-17T13:58:06.411738Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.30).
2022-08-17T13:58:07.176536Z 0 [System] [MY-010116] [Server] /usr/local/mysql-8.0.30-macos12-arm64/bin/mysqld (mysqld 8.0.30) starting as process 1284
2022-08-17T13:58:07.179562Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql-8.0.30-macos12-arm64/data/ is case insensitive
2022-08-17T13:58:07.194523Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-17T13:58:07.269541Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-17T13:58:07.400561Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/tmp/mysqlx.sock' failed, can't open lock file /tmp/mysqlx.sock.lock'
2022-08-17T13:58:07.498398Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-08-17T13:58:07.498450Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-08-17T13:58:07.499048Z 0 [ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: Address already in use
2022-08-17T13:58:07.499068Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3306 ?
2022-08-17T13:58:07.499087Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-08-17T13:58:08.543591Z 0 [System] [MY-010910] [Server] /usr/local/mysql-8.0.30-macos12-arm64/bin/mysqld: Shutdown complete (mysqld 8.0.30) MySQL Community Server - GPL.
I'm not really sure what to do at this point. Any help would be greatly appreciated.
Edit:
To summarize, in System Preferences when I press "Start MySQL Server", it turns on for a few seconds and then turns off again. That is my first issue. The second problem is that if it stays on, I can't log in. I've tried both on the command line and using MySQL Workbench.
The issue was that I had installed MySQL previously with Homebrew and they were both trying to run on port 3306.

MySQL docker container receives SHUTDOWN command

everyone. I have noticed strange behavior during MySQL docker container startup. Basically I'm trying to run the following command
docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.29
but after that I see from the logs that container after successful startup suddenly receives SHUTDOWN command, and reinitialize database again
2022-07-25T19:33:26.423537Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
Here is all the logs:
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Initializing database files
2022-07-25T19:33:19.770157Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 42
2022-07-25T19:33:19.775554Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:20.037982Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:21.277581Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Database files initialized
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Starting temporary server
2022-07-25T19:33:23.494658Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 91
2022-07-25T19:33:23.505604Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:23.590481Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:23.778598Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-25T19:33:23.778621Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-25T19:33:23.779801Z 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.
2022-07-25T19:33:23.790924Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2022-07-25T19:33:23.790961Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
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.
2022-07-25 19:33:24+00:00 [Note] [Entrypoint]: Stopping temporary server
2022-07-25T19:33:24.911894Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.29).
2022-07-25T19:33:26.423537Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
2022-07-25 19:33:26+00:00 [Note] [Entrypoint]: Temporary server stopped
2022-07-25 19:33:26+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2022-07-25T19:33:27.122487Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-25T19:33:27.128121Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:27.217345Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:27.410605Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-25T19:33:27.410659Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-25T19:33:27.412287Z 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.
2022-07-25T19:33:27.431360Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-07-25T19:33:27.431373Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
And after second attempt container is up and running normally. So my question is - how to identify what causes to the SHUTDOWN command?
That's a normal consequence of the way the mysql image runs its first-time initialization scripts. Note the Initializing database files message and the Temporary server started...Temporary server stopped around the first Received SHUTDOWN message.
You can see this logic in the entrypoint script itself. That script runs (using shell functions defined previously in the script, trimmed down somewhat)
# there's no database, so it needs to be initialized
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_init_database_dir "$#"
mysql_note "Starting temporary server"
docker_temp_server_start "$#"
mysql_note "Temporary server started"
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
fi
The mysql_note lines are visible in the container output you quote.
More specifically, the temporary server is accessible over a Unix socket within the container filesystem, but it is not accessible over the network. This gives a point where the database hasn't been set up yet, but it's still possible to run local mysql commands, for example from the initdb scripts. Once this phase has been complete, then the database restarts with its normal options.
If you're probing to see if the database is ready yet, maybe using a mysql client in a shell loop or a TCP client like the wait-for script, this means that the database won't appear "ready" until all of the initdb scripts have run.

mysql : unable to create secondary server instance using mysqld

I am using mysqld to create an new server along with the existing one[ MYSQL 8.0.27 installed with the windows installer] to test data replication
I already have an instance of the server installed [called Mysql80] which is the original server and i am trying to create another server called MyTest using mysqld by reading this documentation which seems simple enough
i have created an empty Data directory to hold my new database and my configuration file for the server is saved as conf.cnf
[MyTest]
port = 3310
datadir = E:/Program Files/Developer/MYSQL/Data/TestFolder/Data
from the windows command line i create the server using their exact instructions
mysqld --defaults-file=E:/conf.cnf --console
--console is used to display debugging information but i always get these error's
021-12-12T17:17:11.844725Z 0 [System] [MY-010116] [Server] E:\Program Files\Developer\MYSQL\Server 8.0\bin\mysqld.exe (mysqld 8.0.27) starting as process 2328
2021-12-12T17:17:11.875406Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-12-12T17:17:13.498780Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Table 'mysql.plugin' doesn't exist
2021-12-12T17:17:13.866706Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.
2021-12-12T17:17:13.867207Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.867617Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.868042Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.868519Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.868926Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.869354Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.869707Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2021-12-12T17:17:13.979431Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-12-12T17:17:14.140027Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-12-12T17:17:14.172455Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-12-12T17:17:14.172592Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-12-12T17:17:14.175122Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-12-12T17:17:14.175319Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-12-12T17:17:14.176633Z 0 [ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: Only one usage of each socket address (protocol/netwo k address/port) is normally permitted.
2021-12-12T17:17:14.176755Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3306 ?
2021-12-12T17:17:14.177195Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-12-12T17:17:15.446688Z 0 [System] [MY-010910] [Server] E:\Program Files\Developer\MYSQL\Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.27) MySQL Community Server - GPL.
Ignoring the optimizer error's and cannot find table error's the server always tries to start on port 3306 even though i have specified in my conf file it should be on port 3310
Which makes me believe that i typed the config file in the wrong format or i haven't specified enough parameters for the job
any ideas?
Turns out i was doing two things wrong
I had previously upgraded from mysql 8 to 8.27 hence tables were corrupted which explained the Optimization errors
My config wasn't in the correct format
After deleting the MySQL service from windows services and deleting my data directory these 3 steps need to be performed in order
Create an new directory to store Data, your config file , upload directory[To Use commands like LOAD FILE]
The structure looks like this
->Warehouse1
|--->Data
|--->Uploads
|--->MyConfig.cnf
Where MyConfig.cnf looks as follows
[mysqld]
basedir="E:\Program Files\Developer\MYSQL\Server 8.0"
port=3306
datadir="E:\Program Files\Developer\MYSQL\Storage\WareHouse1\Data"
secure-file-priv="E:\Program Files\Developer\MYSQL\Storage\WareHouse1\Uploads"
2)Initialize the data directory from your windows command line using mysqld as follows
mysqld --defaults-file="E:\Program Files\Developer\MYSQL\Storage\WareHouse1\config.cnf" --initialize
3)Finally create an service which you can change in Windows Services window
mysqld --install MySQL81 --defaults-file="E:\Program Files\Developer\MYSQL\Storage\WareHouse1\config.cnf"
Repeat the same steps to create an second server.

Mysql installation problems. (The mysql local service started and stopped . Some services...)

I understand that this question has been asked alot of times before with and I have tried everyone of their solutions. It hasn't worked for me. To summarize I'm installing using the windows msi installer version 8.0.22.0 to install mysql. Everything goes fine in the installation until we get to the starting services part of the installation. There it gets stuck at starting server never advancing. I know that's due to the service not starting and I do the recommended step of running services.msc as a service. I'll also paste my error log that I got from the programdata/mysql/mysql server 8.0/ directory.
Important info
mysql version 8.0.22.0
using msi installer
windows 10
2020-11-08T19:46:08.681432Z 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.
2020-11-08T19:46:08.682752Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 17300
2020-11-08T19:46:08.719892Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-08T19:46:09.221182Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-11-08T19:46:09.369387Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2020-11-08T19:46:09.464341Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-11-08T19:46:09.465186Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-11-08T19:46:09.477256Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-000001 - Can't create/write to file 'C:\ProgramData\MySQL\MySQL Server 8.0\Data????.pid' (OS errno 2 - No such file or directory)
2020-11-08T19:46:09.479597Z 0 [ERROR] [MY-010092] [Server] Can't start server: can't create PID file: No such file or directory
2020-11-08T19:46:09.485610Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-11-08T19:46:10.655699Z 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.
The questions I've looked at
the MySQL service on local computer started and then stopped
The MSSQLSERVER service on Local Computer started and then stopped. Some services stop automatically
You have to check in your my.ini which is located in C:\ProgramData\MySQL\MySQL Server 8.0\
Can't create/write to file C:\ProgramData\MySQL\MySQL Server 8.0\Data????.pid
As you can see the correct path would be
[mysqld]
pid-file = "C:/ProgramData/MySQL/MySQL Server 8.0/Data/????.pid"