No database connection via doctrine in symfony - php

I'm working on the symfony tutorial jobeet and I have problems to get a database connection to the MySQL-database via doctrine. Development enviroment: Mac OS X and XAMPP.
The command php symfony doctrine:build-schema gives me the following error message:
Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/xx/projects/myproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 470
PDO Connection Error: SQLSTATE[HY000] [2002] No such file or directory
The database settings in the database.yml:
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=my_project_db'
username: root
password: root
MySQl is running. Username and password are correct. The database 'my_project_db' exists.
Could anybody give me a hint what's going wrong?

Try to create a symlink in /var/mysql to your mysql.sock:
sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql /var/mysql

Or with MAMP
cd /var; sudo ln -s /Applications/MAMP/tmp/mysql mysql

On Mac OSX Lion:
cd /var;
sudo mkdir mysql; cd mysql;
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock

I had the same problem on my apple mac and did the following:
cd /var; sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/ mysql
Worked for me.

This situation also happened to me and I use MAMP Pro. If you use MAMP Pro, its worth checking the main window. Look at "MySQL" tab, and then see "Allow local access only" checkbox. If it is checked, you should uncheck it. Finally, click, "Apply" button.

Related

Connection for controluser as defined in your configuration failed on ubuntu20.04 container

I'm trying to have one docker container with: ubuntu 20.04, on top of which I add apache, php, mysql and phpmyadmin (all on the same container)
What's installed:
mysql Ver 8.0.29-0ubuntu0.20.04.2 for Linux on x86_64((Ubuntu))
Apache/2.4.41 (Ubuntu)
phpmyadmin 4:4.9.5+dfsg1-2
PHP 7.4.3
This is the content of my dockerfile:
FROM ubuntu:20.04
MAINTAINER Myself
RUN apt-get update
RUN apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt -y install apache2 php libapache2-mod-php mysql-server php-mysql phpmyadmin
# I've set the dbuser to 'admin' dbpass to 'admin' here
COPY ./config-db.php /etc/phpmyadmin/config-db.php
RUN cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
RUN a2enconf phpmyadmin
COPY ./start.sh /start.sh
COPY ./init.sh /init.sh
RUN bash /init.sh
CMD ["bash", "start.sh"]
And this is the content of my init.sh:
#!/bin/bash
service mysql start
# I'm creating the phpmyadmin database here
mysql -u root --password= < /usr/share/phpmyadmin/sql/create_tables.sql
mysql -u root --password= -e "CREATE USER 'admin'#'localhost' IDENTIFIED BY 'admin';"
mysql -u root --password= -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'#'localhost';"
mysql -u root --password= -e "FLUSH PRIVILEGES;"
mysql -u root --password= -e "CREATE DATABASE PROJECT_MANAGEMENT;"
And this is the content of my start.sh:
#!/bin/bash
service mysql start
apachectl -D FOREGROUND
I run my container through docker build -t test . and docker run -d -p 80:80 test (even tried to add -p 3306:3306...). I can access apache2 through localhost:80 and I'm pretty sure mysql is up because my queries worked.
But logging in to localhost/phpmyadmin with username:admin and password:admin just won't work: " Cannot log in to the MySQL server", " mysqli_real_connect(): (HY000/2002): Permission denied", " Connection for controluser as defined in your configuration failed.", " mysqli_real_connect(): (HY000/2002): Permission denied"
(Yes, I have tried to set controluser and controlpass in config.inc.php to admin/admin)
I have no idea what i have to do, I'm overly frustrated, i've tried everything that was on the internet.
Thank you
QUICK-FIX: For some reason phpmyadmin doesn't add the port to the request: I had to set the following in the file /etc/phpmyadmin/config.inc.php: $cfg['Servers'][$i]['host'] = "{$dbserver}:{$cfg['Servers'][$i]['port']}"; after the port directive was set of course.
If someone has a good explanation that'd be greatly appreciated!

Cannot access phpmyadmin locally

I am aware that this has been answered multiple times, I get the 1045 error, I am trying to follow https://www.ostraining.com/blog/coding/error-1045-phpmyadmin/, but get this when trying to follow the steps:
Michaels-Air:~ michaelnares$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Michaels-Air:~ michaelnares$ cd /tmp
Michaels-Air:tmp michaelnares$ ls
com.apple.launchd.Uoy1kKt9Ag com.apple.launchd.bRUV1JxWGF mysql.sock.lock
Michaels-Air:tmp michaelnares$
Doing sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock doesn't create the necessary file, what else can I do please?
Is it possible that your mySQL instance is not running?
To check use:
ps aux |grep mysqld
brew reinstall mysql worked, not quite sure why.

MariaDB remote access

I am using laravel 5.4 and on remote server ubuntu 16.04 with latest mariaDB,
I made almost all the configuration listed in google and also i revert to the original state.
My current problem is that i cannot connect to my remote mariadb. Credentials are absolutely fine.
I changed the /etc/mysql/mariadb.conf.d/50-server.cnf file for the bind-address where i gave the ip of the server, The ip where i can access my phpmyadmin like 1.1.1.1/phpmyadmin. Current .env setting is :
DB_CONNECTION=mysql
DB_HOST=1.1.1.1
DB_PORT=3306
DB_DATABASE=*******
DB_USERNAME=root
DB_PASSWORD=********
But the error it throws SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it..
Check your AppArmor profiles. It may be blocking the mysqld process from accessing network.
$ sudo apparmor_status
Make sure mysqld is not in any "enforce" mode.
Check to see if there is a mysqld profile in /etc/apparmor.d/
$ ls /etc/apparmor.d/*mysqld*
To disable it, put a simlink in /etc/apparmor.d/disable/
$ sudo ln -s /etc/apparmor.d/<full_name_of_mysqld_file> /etc/apparmor.d/disable/
followed by
$ sudo apparmor_parser -R /etc/apparmor.d/<full_name_of_mysqld_file>
Verify that mysqld protection is disabled:
$ sudo aa-status

Database SQL Dreamweaver connecting

When i connected mySQL databases to dreamweaver I only saw the default databases, none of the ones I created in myPHPadmin, I am running MAMP 2.2 on Mac OS X 10.7.5 Dreamweaver CS6, I am going to the databases icon on the right side of the screen in "App Developer Plus" viewing mode. I am trying to add a database with mySQL connection:
Connection Name: registration, mySQL server: localhost, Username: root, Password: my set password, Database <--- here is the error when I click select; it does not show the databaes I made in myPHP admin. called Registration and Dbank; I'm expecting to see these databases as I can see them in myPHPadmin. but in Dreamweaver after connecting to mySQL i only see: information_schema. mysql, performance_schema, and test.
Nothing seemed to work.. so I thought it could be an error created when i had installed mysql before installing MAMP, So i removed mysql standalone, and when I removed mysql, the databases no longer connected at all in dreamweaver. I got an error:
MySQL Error #2002
No such file or directory so THEN I have tried
Formating my computer and reinstalling all Dreamwweaver, MAMP, and re-enabling everything --> SAME ERROR :(
Setting the path in terminal to include /Applications/MAMP/Library/bin/mysql in .bash_profile --> SAME ERROR :(
In Terminal doing:
cd /var/
sudo mkdir mysql
cd (to get back to root)
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
--> SAME ERROR :(
Why can't Dreamweaver just connect to the databases.? PLEASE HELP!

Trying to connect to mysql server for the first time and get an error messange: "mysql: command not found"

I am setting up my first data base using XAMPP. I followed the steps from
dev.mysql.com/tech-resources/articles/mysql_intro.html
but as I try to connect to mysqlserver by typing "mysql -u root" into my Terminal I get back an error message:
Phosphoros:~ Arthur$ mysql -u root
-bash: mysql: command not found
Phosphoros:~ Arthur$
I am using Mac OS X 10.7.5.
How can I connect to the server?
Arthur
Your terminal application doesn't know where to locate the mysql program.
For example, if you installed xampp in C:/xampp, you open a command prompt, cd to C:/xampp/mysql/bin and then run your command, which should work now.
Edit: Just remembered you mentioned OSX, regardless, use the same principle. In your terminal, cd to the XAMPP install subfolder which contains the mysql executable app
you have to run the command: mysql -u root in the mysql directory that exists in the /opt/lampp directory.

Categories