I have MySQL server running on a different port than the default one.

Suppose, the default port for MySQL is 3306. I have another MySQL server running on port 5625. I want to install Magento2 using MySQL database from port 5625.

While installing Magento2, I can only specify hostname, username, password and database name.

How can I specify port number as well at the time of installation?


3 Answers 3


If you use the CLI, you can append the port to the --db-host flag. You can probably do the same thing in the Setup Wizard.

IOW, --db-host=localhost:5625


If you're using docker; make sure to not use localhost as given. - Use the container name such as 'mysql'. - So when you're in the setup just give it your container name.


Magento takes default database port to 3306. In case of the port 3306 used by any other application and mySQL is running on another port then we can use that new port by passing port number with the database host.


Here 3307 is a port which bind with the MySQL.

So, a full command will be to install the Magento:

php bin/magento setup:install \
--base-url=https://magento244.test \
--db-host= \
--db-name=magento2 \
--db-user=root \
--db-password=root \
--admin-firstname=Mage \
--admin-lastname=Smoker \
[email protected] \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-host=es-host.example.com \
--elasticsearch-port=9200 \
--elasticsearch-index-prefix=magento2 \

If you getting error to run above command then you can put in a single line and install to:

php bin/magento setup:install --base-url=https://magento244.test --db-host= --db-name=magento2 --db-user=root --db-password=root --admin-firstname=Mage --admin-lastname=Smoker [email protected] --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host=es-host.example.com --elasticsearch-port=9200 --elasticsearch-index-prefix=magento2 --elasticsearch-timeout=15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.