I have both xampp
, mysql community server
Installed on my Ubuntu 22.04
.
since both xampp/phpmyadmin
and mysql community server
listen to port 3306
,
I have changed mysqli.default_port=3307
in /opt/lampp/etc/php.ini
and I have also added a line right under [mysql]
in /etc/mysql/conf.d/mysql.cnf
saying port = 3307
.
Now I have also extracted hostname from my mysql using this commands
service mysql start
mysql -u root -p
show variables like '%host%';
which said my host name is
solo-ROG-Strix-G731GV-G731GV
and I also created a user with all grants on a database like
create database test;
create user 'test'@'solo-ROG-Strix-G731GV-G731GV' identified by '1234';
grant all privileges on test.* to 'test'@'solo-ROG-Strix-G731GV-G731GV';
flush privileges
and then I made sure phpmysqladmin was not running by only running xamppapache using
cd /opt/lampp/
sudo ./xampp startapache
and here is my php code to connect to mysql community server
<?php
const MYSQLI_HOSTNAME = "solo-ROG-Strix-G731GV-G731GV";
const MYSQLI_ADMIN_USERNAME = "test";
const MYSQLI_ADMIN_PASSWORD = "1234";
const MYSQLI_DATABASE = "test";
$db_admin = new mysqli(MYSQLI_HOSTNAME, MYSQLI_ADMIN_USERNAME,
MYSQLI_ADMIN_PASSWORD, MYSQLI_DATABASE
, 3307);
if($db_admin->connect_error){
echo $db_admin->connect_error;
}
and now it’s saying connection refused
full error
Fatal error: Uncaught mysqli_sql_exception: Connection refused in /opt/lampp/htdocs/baharshop/src/lib/db/db_admin.php:2 Stack trace: #0 /opt/lampp/htdocs/baharshop/src/lib/db/db_admin.php(2): mysqli->__construct('solo-ROG-Strix-...', 'test', Object(SensitiveParameterValue), 'test', 3307) #1 /opt/lampp/htdocs/baharshop/config/config_admin.php(17): require_once('/opt/lampp/htdo...') #2 /opt/lampp/htdocs/baharshop/admin/dashboard.php(3): require_once('/opt/lampp/htdo...') #3 {main} thrown in /opt/lampp/htdocs/baharshop/src/lib/db/db_admin.php on line 2`
I mean what else needs to be done?
I tried changing ports on both php.ini and mysql community server
2
Answers
I ended up changing xampp/mysql/phpmyadmin port because that was easier and left the the mysql community workbench to have it's default port since I was on linux it was harder to locate mysql community workbench config files. it might help someone in future
port = 3307 should be in the [mysqld] option in the parameter file, not [mysql]. Changing the port requires restarting the database service.