I'm trying to set up an e2e test. For this, I need a local test database, preferably in Docker so that test setup is simple. Here is a minimal project showing what I currently have: https://gitlab.com/MakotoE/mysql-test If this issue is fixed, npm test will finish with exit code 0. This is being run on Windows 10.
In main.js, I start an instance of the Docker image mysql:8.0 like this:
const command = 'docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -p 3306:3306 -d mysql:8.0';
ChildProcess.execSync(command);
I want to connect to it with mysql2, but it fails with an Error: connect ETIMEDOUT.
await mysql.createConnection({
host: 'localhost',
user: 'root',
});
If I try to connect to the database created in the JavaScript code, through command prompt (mysql -uroot), I get this error: ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0. If I create the container in command prompt with the same docker run command used in the code, I can connect successfully, so this issue might be related to ChildProcess.execSync, but I don't know how I can fix this.
How can I fix my code so that I can start a MySQL server in Docker and connect to it in Node.js running on Windows 10?
Edit: I'm not sure if this is related, but running this on Debian shows this error message when creating the container:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:
Post http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/57f5b631e551466e1f9928ba62f7a5e2a5ad2a481da4686bda8684f1a71b8d7/stop: dial unix /var/run/docker.sock: connect: permission denied
And connection fails with ETIMEDOUT.
Edit: I added branch secondAttempt where I unsuccessfully tried running all commands outside the .js file, through NPM scripts. After running the test for this branch, you must manually stop the Docker container.
In the mysql -uroot command, it fails with:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
which I believe is the same error as experienced previously, with different messages (due to different clients).
This experiment tells me two things: ChildProcess.execSync is not the root cause to this issue, and that there is something about this system (whether it is Docker, or the TCP connection to the Docker) that prevents scripted commands.
I finally figured this out. All I need to do is wait 15 seconds before connecting.
The mistake I made is a common one: not reading the readme. In the mysql Docker Hub page, under section "No connections until MySQL init completes", it mentions how you must wait for database initialization to complete. The example repos achieve this via looping to retry the connection, but I think its simpler to delay for a set period of time.
Before, I was under the impression that I only needed to wait ~1 second after docker run, but actually it takes ~14 seconds for the database to be initialized. The fix was as simple as using setTimeout to wait 15-20 seconds before connecting to the database. I have given an example in branch fixed!.
Related
Error Message is:
Warning: mysqli::__construct(): (HY000/1130): Host 'host.docker.internal' is not allowed to connect to this MySQL server in E:\wamp64\www\FISH\test13\records.php on line 61
Error failed to connect to MySQL: Host 'host.docker.internal' is not allowed to connect to this MySQL server
On Windows 10, using VSCode, wamp, localhost, mysql
Was working fine, then I installed Docker Desktop on Windows
Was having trouble understanding Docker, so I uninstalled it from Control Panel ->Programs and Features.
Now when I return to localhost website, I get the error message (as above).
I have additionally removed any reference to 'docker' using regedit.
I removed all files 'docker' from file system.
Rebooted.
root user has full access to database as confirmed in:
Server: MySQL:3306 »Database: mysql »Table: user“Users and global privileges”
Any ideas how to remove error message and get system working again? Or do something to just move on from this error?
I have an application which uses LocalDB and runs fine on a Windows PC, however I am trying to run this through my mac.... I'm struggling with connecting the application to a mySQL server which sits on docker. I have been following the other guides such as (https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash) related to this topic with no luck...
Here's what I've done so far, through terminal:
sudo docker pull mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<MyPassword123!>"
-p 1433:1433 --name sql_container
-d mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04
Verified this is running by using sudo docker ps -a
Also verified by using Kitematic, container seems to be running well
MySQL looks well set-up in System Preferences
I am able to connect to the container through Azure Data Studio using IP address as server name, as shown below
Within the Application, this is is what the ConnectionStrings look like within the appsettings.json folder...
However, when I run the application and try and hit the container, through a GET request OR on Swagger, I am met with the following reply; "error": "Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started."
I have researched this and tried the solution of including the port number after the IP number as such Server=(19X.XXX.X.XX, 1433) but this also comes back with the error; "error": "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)"
I'm not sure where to go from here... any help to get this working would be greatly appreciated!
As trivial as it was, the correct syntax to make this work is Server=XXX.XXX.X.XX,1433
DO NOT INCLUDE PARENTHESES AND NO SPACE BETWEEN IP AND PORT
MySQL works fine until I start my game server. When I start my game server, I get the error "Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306"
If I run the webserver after running the game server, I will get that error as well, but if I run the webserver first, it works fine UNTIL I run the game server.
Similarly if I do mysql -u root -p and try to log in after I start the game server I get the error
' Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' '
I can literally use mysql -u root -p up until I get the first error message from the game server. Does anyone know why this is happening?
I've been attempting pretty much all day to get Symfony2's Doctrine configuration screen (e.g. /app_dev.php/_configurator/step/0) to connect to my locally running MAMP-provided MySQL instance. I've spent the day reading about sockets, skip-networking, and every other possible scenario but I'm at a loss. This is the error that you have most certainly seen before:
An exception occured in driver: SQLSTATE[HY000] [2003] Can't connect to MySQL
server on '127.0.0.1' (61)
And here are the various ways I have tried to correct this maddening problem:
I verified that I can indeed connect on the command line to both localhost and 127.0.0.1 using the mysql command. I made sure the ports were both filled in and not so I could see the results of an actual error.
I checked the socket while I was in there via SHOW variables LIKE 'socket' and saw it pointed correctly to my MAMP socket.
I've oscillated between the MAMP default ports and the standard MySQL ports (3306) just in case it was a weird port thing.
I made sure my /var/mysql and /tmp/mysql mysql.sock files were correctly symlinked to MAMP.
I commented out the skip-networking lines in MAMP's configuration file.
I toggled the "Allow Network Access" in every configuration possible
I added the line, unix_socket: /Applications/MAMP/tmp/mysql/mysql.sock, to my config.yml file just in case my symlinking trickery failed me.
I've done several rain dances and other tribal spells I read in a magazine trying to get this to connect.
I'm no stranger to development and MySQL but this has become a lost cause. Any help would be appreciated and rewarded with my unflinching respect for you.
The error code 2003 means "Can't connect to MySQL server", you can try to use the following methods.
Check your config file, is the parameters.yml can be access ? If you are on linux, just sudo chmod 777 /path/to/parameters.yml, and the mysql connection config parameters looks like this:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1 or localhost
database_port: null
database_name: yourdbname
database_user: youraccount
database_password: yourpassword
Try to use localhost instead of 127.0.0.1;
I have mysql installed several months ago. However I do remember using mysql workbench successfully at one point of time. Today I try launching it and get following error
Lost connection to MySQL server at 'reading initial communication packet', system error: 61
open /etc/mysql/my.cnf in a text editor and try changing:
bind-address = 127.0.0.1
to
#bind-address = 127.0.0.1
and then restart MySQL.
Try using the connection method: Local Socket/Pipe.
If you are trying to use the MySQL Workbench and connect through an SSH tunnel, you will get this error when your SSH connection does not complete successfully (e.g. improper host, password, key file, etc)
A good way to trouble shoot this is to separately test the the ssh connection from the machine you are trying to connect from and establish that you can do so succesfully.
I came across the same problem.I fix this below:
3306 port may be occupied by other process, so mysql change the port to 3307(or nearly other port 3308...).So when you connect,change the port to 3307 and try