To access a MySQL database from your PHP scripts, you can use localhost or 127.0.0.1 as database server name in your connection string. The database port will depend on the MySQL version of your database. For MySQL 5, you can use 3306 (the default port), while for MySQL 8, you will need to use port 3308. If your script supports UNIX sockets, you can use /tmp/mysql8.sock as socket for MySQL 8.
Here is an example connection string for MySQL 5:
mysqli_connect('localhost', 'mysql_user', 'mysql_password','mysql_database');
Since the default port is used, there is no need to define the port for MySQL 5 connections.
Some applications may not work correctly with ports, so you may encounter issues when connecting to your MySQL 8 database. In such events, you can refer to the following example connection strings for MySQL 8 which use different settings:
mysqli_connect('127.0.0.1:3308', 'mysql_user', 'mysql_password','mysql_database');
mysqli_connect('127.0.0.1', 'mysql_user', 'mysql_password', 'mysql_database', '3308');
mysqli_connect('localhost', 'mysql_user', 'mysql_password', 'mysql_database', null, '/tmp/mysql8.sock');
You can find the correct database server settings for MySQL 8 for some of the most popular software applications in our MySQL 8 database server settings article.
All prices are in USD. No setup fees. Minimum contract period for shared hosting services - 12 months. Full prepayment for the contract period. 100-day money-back guarantee. No automatic renewal. Fees for domain registrations and SSL certificates cannot be refunded in case of an early contract termination.
ICDSoft 2001-2024 © All rights reserved
Terms of Use
|
Legal notice
|
Privacy
|
Reseller terms