i think this might be a stupid question for some, but i swear that i can't find the answer by myself actually.
I'm still learning Symfony so please be nice.
Actually i have set up the access to my database in the .env file :
[...]
DATABASE_URL=mysql://root:db_password#127.0.0.1:3308/db_name
[...]
And then i have define the environnement variable in the config/doctrine.yaml :
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: Symfony
user: root
password: null
host: localhost
server_version: '8.0'
driver: pdo_mysql
charset: UTF8
So i run the following command :
> php bin/console doctrine:database:create
But the 'Symfony' database have been created under mariadb.
:( I don't understand why because i have define precisely that i use a 8.0 version and this version is not a mariadb version.
I've also try this :
# .symfony/services.yaml
mydatabase:
# supported versions: 5.7, 8.0
type: oracle-mysql:8.0
disk: 1024
As the symfony documentation saying to do, but it still not working at all.
I have got the following error message as mydatabase is not a symfony services :
C:\Users\vincp\Symfony\charming_tuto>php bin/console doctrine:database:create
In FileLoader.php line 173:
There is no extension able to load the configuration for "mydatabase" (in "C:\Users\vincp\Symfony\charming_tuto\con
fig/services.yaml"). Looked for namespace "mydatabase", found ""framework", "sensio_framework_extra", "twig", "twig
_extra", "web_profiler", "monolog", "debug", "webpack_encore", "doctrine", "doctrine_migrations", "maker"" in C:\Us
ers\vincp\Symfony\charming_tuto\config/services.yaml (which is being imported from "C:\Users\vincp\Symfony\charming
_tuto\src\Kernel.php").
I wanna use mysql because this is the DBMS that i use usually.
(If you think that i should use mariadb instead of mysql i'm open to that, but give me some arguments. I'd be really interseted in)
Maybe it is a server issue. So first, make sure that MySQL is running on your server besides MariaDB (how to do it depends on the type of server you are using).
If yes, it might be a port setting issue: I see that you set the database port to 3308. That is probably the port on which MariaDB is listenning. Try to determine if there is another db running on your server listening to another port (for example 3306 is very often the default MySQL port). To do so, on a Linux server you could try the following command :
netstat -tlnp | grep mysql
If you find only x x.x.x.x:3308 address or so, I bet that MySQL is not running on your server and you only run a MariaDB instance. But if you find addresses on other ports (for example x x.x.x.x:3306) chances are that a MySQL instance is running and listens that other port. If that's the case, you should consequently change the DATABASE_URL in your .env file.
Related
TL;DR: Trying to fix error before it occurs, not when it happens, as in related questions
First up: I know the error says to run an upgrade script for the DB.
However: I'm running this in Docker. I'm also getting this error after removing the container and the image and creating a new, clean instance.
The database is created by Doctrine, configured for MariaDB 10.5.8 (same version as DB configuration in Docker (see below)).
However, after dumping tables, recreating the db schema and then refreshing the setup in the IDE (PhpStorm) I get this notification:
Error encountered when performing Introspect schema workflow_poc: Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 50731, now running 100508. Please use mariadb-upgrade to fix this error.
Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 50731, now running 100508. Please use mariadb-upgrade to fix this error
From that I read that the schema was created with a MariaDB 5.7 configuration and now we're running MariaDB 10.5. However, nowhere am I using version 5.7 in this setup.
Any ideas on how to fix this before the error appears and without a hack to include the upgrade command somewhere?
Docker config:
db:
image: library/mariadb:10.5.8
volumes:
- "mysql_data:/var/lib/mysql:delegated"
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-project_name}
- MYSQL_DATABASE=${MYSQL_DATABASE:-project_name}
- MYSQL_USER=${MYSQL_USER:-project_name}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-project_name}
- TZ=Europe/Amsterdam
ports:
- "${MYSQL_PORT:-30026}:3306"
Symfony Doctrine config in doctrine.yaml
doctrine:
dbal:
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
driver: 'pdo_mysql'
server_version: 'mariadb-10.5.8'
url: '%env(resolve:DATABASE_URL)%'
A brief summary of my question:
What characteristic of my docker-compose is colliding with PDO that prevents Host -> mysql-docker via PDO, but allows Host -> mysql-docker from all other tools?
My App's config file:
database:
host: mysql
port: 3306
name: <name>
username: <username>
password: <pass>
outsideContainerConnections:
host: 127.0.0.1
port: 3307
Everything is running fine within the container, and I am able to access the database from the host using PHPStorm or Mysql on the command line.
If I run this command from the host, it connects
mysql --port=3307 -h 127.0.0.1 -u <username> -p
However, if I try to connect from php on the host, using PDO, it fails with
PDOException: SQLSTATE[HY000] [2002] Connection refused
PDO DSNs I've tried:
mysql:host=127.0.0.1:3307;port=;dbname=<name>;&charset=utf8;
or
mysql:host=127.0.0.1;port=3307;dbname=<name>;&charset=utf8;
or
mysql:host=127.0.0.1:3307;dbname=<name>;&charset=utf8;
I have read about using localhost vs 127.0.0.1 to force TCP, and I am doing that here.
Here also is the relevant section of my docker-composer. Again, using command line or other tools from the host work fine, it is only PDO that seems to have an issue. For what it's worth, PDO on another container in the docker-compose network is behaving.
mysql:
build: './mysql_docker'
command: --lower_case_table_names=0
ports:
- '3307:3306'
volumes:
- ./volumes/mysql:/var/lib/mysql
- ./volumes/my.cnf:/etc/my.cnf
networks:
- app-tier
Thank you for reading.
I've solved it– it's simple but hopefully a good lesson to pass on.
In one case the PHP file was being run by cron, and so it was being run locally, outside of the docker container. I had a small syntax or other error in my file so cron was having some trouble.
In order to debug this situation, I was opening the file in my web browser–and that's the kicker. The connection errors I saw in the web browser were not the same problems cron was having, because that page was being served by the docker container. Thus, the connection details had to be different. The same setup could not work both from the host and from the neighbor container.
What I learned is this; what seems like a really heady technical problem that requires lots of manual reading and research COULD be a simple bad assumption. Sometimes it's worth going back to the drawing board and sketching an outline of the situation from the ground up.
In a way that is what I did with asking this question, so thank you for the space to do so.
try "mysql --port=3307 -h 127.0.0.1 -u -p" from client if no
I am trying to connect Symfony 2.8 to Microsoft SQL Server 2012 by using sqlsrv extension (no pdo sqlsrv, because for php7 - which I am using - there is currently only non pdo).
Trying to run cache clear or access the site in browser results in
"PDO::__construct(): MySQL server has gone away".
When I run the doctrine schema update command, everything works fine and the tables are being generated. Does anyone know how to fix the error? (I don't even know why it says Mysql server gone away when I try to connect on microsoft sql..)
Config:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: sqlsrv
host: testhost
dbname: testdb
user: testuser
password: testpw
mapping_types:
timestamp: string
I am looking for a solution since Friday but was not able to find one. I tried to select some entries from a seperate (non symfony) php skript, and there I got the results and no timeout. Why is Symfony / Doctrine giving me this strange error?
you can try to launch this command for doctrine :
php app/console doctrine:cache:clear-metadata
php app/console doctrine:cache:clear-query
php app/console doctrine:cache:clear-result
Also perhaps upgrade and downgrade your doctrine bundle for restore a correct and initial version of bundle for your project.
I am using phinx for migrations in my web app.
my phinx.yml:
paths:
migrations: %%PHINX_CONFIG_DIR%%/migrations
environments:
default_migration_table: app_migrations
default_database: app_database
development:
adapter: mysql
host: localhost:8888
name: app_database
user: ''
pass: ''
port:8889
I have mamp with ports apache:8888 and mysql:8889 running.
The database app_database does exist.
The table app_migrations does not exist(it will be created while migrating right?)
I already created some migrations and now i try to run them:
php vendor/bin/phinx migrate -e development
output in console:
Phinx by Rob Morgan - https://phinx.org. version 0.5.1
using config file ./phinx.yml
using config parser yaml
using migration path /path/to/directory/migrations
using environment development
using adapter mysql
using database app_database
Then it stops and nothing happens...
Anybody could help me with this issue?
Thanskj and Greetings!
Maybe there is some config-hickup. I know this phenomenon from conneting to a mysql-database that is not reachable via a specific host / port. This always leads to timeouts but only after eg. 60 seconds.
You wrote this in your config:
host: localhost:8888
[...]
port: 8889
First remove the port from the hostname:
host: localhost
port: 8889
and as second verify the mysql-server is really listening on localhost / port 8889.
You'll find more on in the "Configuration"-chapter of phinx-documentation: http://docs.phinx.org/en/latest/configuration.html
Regards
If you're using the default settings for MAMP, the username for the database would be root. Try changing the value of user in phinx.yml to root.
I'm having an issue with Doctrine2 that seems like a bug but I can't find anyone else on Google with the same problem. I'm hoping somewhere here has experienced this problem and knows how to solve it.
Basically I'm trying to connect to a DB2 database. I prefer to use the ibm_db2 client as it's supposed to be better and faster (than PDO_IBM or PDO_ODBC). I've installed the client and tested it. Everything seems to work there. But when I use Doctrine I get the following error:
Notice: Undefined index: protocol in
...[my folders].../vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/
IBMDB2/DB2Driver.php line 54
So in that file it's looking for $params['protocol'] which seems to have no defaults. So in config.yml I tried this:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
protocol: TCPIP
But when I do that it complains that protocol is an undefined configuration option (and looking through the DependencyInjection stuff it doesn't appear anywhere in there.)
However: if I hard-code TCPIP into the Driver file where the error occurs ... it all works. This is undesirable since it involves changing the vendor supplied file. Has anyone found a way to properly specify the protocol in configuration?
Eventually you're going to run into licensing issues using ibm_db2 as noted here. PDO or ODBC are going to be your only free ways to go. IBM requires DB Connect to use ibm_db2 db2_connect() stuff.