Is there a way to reset all configuration in MySQL? - mysql

I need your help again.
Is there a way to reset all configuration in MySQL?
Here's what happened. I previously have a project installed and this time I'm setting up a new one.
In this new project, I wanted to set it up with my a new database, new username I created and password. However, when I reached the point where I had to execute php artisan migrate, it keeps throwing me an error saying PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
If not that error, it's throwing connection refused instead.
Note: I'm using laradock.
Now, I'm at the point where I'd just rather reset the whole MySQL because I'm thinking it's conflicting with my previous configuration with my previous project.
As I searched online, I've tried the following:
1. Restarted server
2. Changed db_host from 127.0.0.1 to localhost and vice-versa
3. Added the project's directory to the dev environment setting
4. Docker-compose down and then up again
5. Even uninstalled and reinstalled docker itself
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=newdbname
DB_USERNAME=newusername
DB_PASSWORD=newpassword!
All I want is to be able to execute php artisan migrate using the new credentials I set.

If you really do not need any old data in database, you can just delete them & reset up a container:
# stop mysql service
docker-compose stop mysql
# delete old mysql database
rm -rf ~/.laradock/data/mysql
# resetup mysql container
docker-compose up -d nginx mysql
You can get the mysql database location according to docker-compose.yml & env-example:
docker-compose.yml:
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
env-example:
DATA_PATH_HOST=~/.laradock/data

Related

Phpmyadmin stops connecting to mysql server after being up for a few months

I have a docker container running MySQL and another docker container running phpmyadmin. Both containers are running on my Ubuntu server.
Normally I can log into MySQL without problems thru phpmyadmin. However, this has happened several times in the past, that phpmyadmin runs into some issue and says:
"Cannot log in to the MySQL server" and
"mysqli::real_connect(): (HY000/2002): No such file or directory".
The funny thing is this happens at seemingly random times before giving this error. One time it worked for 4 months before giving this error message, another time it was 1 month, another time it was 3 months. There didn't seem to be any periodic or specific amount of time before it gave me this error.
I also checked the mysql container and it's still up and running and when I log into it (mysql container), I can access my db and see all the data and tables in it.
When I start the phpmyadmin container, I use this command. There is no config.user.inc.php file in /etc/phpmyadmin and it works for a few months.
docker run --name myadmin -d --link mysql_db_server:db -p 8080:80 phpmyadmin
I found some stackoverflow questions that were similar to my issue but doing what is suggested doesn't work.
One person said to edit the config.user.inc.php file and change the host to 127.0.0.1. I used the config.sample.php as my template for config.user.inc.php. In my config.user.inc.php file, I added
$cfg['Servers'][$i]['host'] = '127.0.0.1';
I then mounted a volume on my local linux server to map to /etc/phpmyadmin on the container such that when we started the container, it would use the config file. I ran:
docker run --name myadmin -d --link mysql_db_server:db -p 8080:80 -v /local/dir/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php phpmyadmin
However, this is worse than when I run the docker command without the volume because using the config.user.inc.php file makes me run into the error immediately. It's almost if the config.sample.inc.php file was misconfigured
The work around for me is to wait for phpmyadmin to give me the error, stop and kill the phpmyadmin container, then start a new one. However, if I can get it to work right off the bat and not run into this error, that would be most ideal.

Where docker stores mysql settings

I am facing one issue with docker, L am using laradock docker env for laravel. Since it has issue with mysql version I had to run those command:
$ docker-compose exec mysql bash
$ mysql -u root -p
ALTER USER 'root'#'localhost' indentified WITH mysql_native_password BY 'root';
Also imported database through http://localhost:8080 and phpmyadmin
So I am trying to reproduce this issue again, so I deleted everything from docker with
$ docker system prune
but when I rebuild the containers
sudo docker-compose up -d nginx mysql phpmyadmin workspace
My previous database is loaded again.
So my question would be how to delete db and MySQL settings, so I can execute the alter command and import database again.
Overall I am trying to determine if this issue with MySQL will occur on another platform again, so I am trying to reproduce it from scratch and that is why I need to reset completely MySQL env and databases.
So not sure where MySQL settings are stored and how to delete them.
MySQL is storing most of the important information of your container in a volume.
Now, the command:
docker system prune
do not remove the volumes, per default.
If you also want to remove them, you can run:
docker system prune --volumes
If you do want to list or act on those specific volumes:
docker volume --help
would give you all the commands on volumes like rm, ls, ...

Docker-How do I connect to mysql container using a karaf container?

Im having some trouble filling my DB when installing a kar on karaf (Im using liquibase).
Im using windows 10, but using linux containers in docker, karaf 4.2.1 and mysql 5.7
There are the steps I did:
1-Went to task manager and stoped the mysql service.
2-Created and run a mysql 5.7 container doing the following:
docker run --name mysql-container -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
Connected using 127.0.0.1 root/root in heidiSql and created the required DB's so when installing the kar liquibase will fill them with data.
3-Copied the kar to the repo folder in my karaf folder, added the folder to .tar, and then to gzip (.tar.gzip)
4-Created my karaf container using:
.\build.sh --from-local-dist --archive apache-karaf-with-kar.tar.gz
5-Did run karaf in the background:
docker run -d -p 127.0.0.1:8101:8101 --name=karaf-container karaf
Now I used putty and ssh to connect to karaf - localhost:8101. enter the user karaf and pass karaf.
All ok, I do the kar:install command, kar install but the bundles are in grace period.
I go to heidiSql and see that the DB's are not filled with data.
I go back to karaf connection, do a feature:refresh and i get erros like:
Error resolving artifact org.ops4j.pax.transx:pax-transx-features:xml:features:0.3.0: [Could not transfer artifact org.ops4j.pax.transx:pax-transx-features:xml:features:0.3.0 from/to central (http://repo1.maven.org/maven2/): Failed to transfer file: http://repo1.maven.org/maven2/org/ops4j/pax/transx/pax-transx-features/0.3.0/pax-transx-features-0.3.0-features.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.]
I suposse the problem here is that somehow my connection to mysql doesn't work.
After some time the ssh connection is lost (I suposse this is normal if I dont do anything for some time there).
I tried to create a mysql-server container instead, but that way im not even able to connect using heidiSql.
Adicional question:
1-Where do I find the link to the kubernetes dashboard? I cant find it on docker.
2-I was having a first error when trying to docker run karaf:
\"karaf\": executable file not found in $PATH": unknown.
I resolved that because I realised that my karaf folder had less files than a downloaded binary one.
Basically the files are the files you see when you open the folder, the build.md, license, etc...
So I did copy paste to my folder of those files and I was able to run it. Im asking, because its still a mystery to me...
Thanks for your attention
edit: tried stoping the mysql-container and started mysql from the task manager and its the same, now im sure that for some reason its not connecting to the DB's. so I guess the problem is when I create a karaf container, maybe im missing some configurations. gonna keep trying
After 2 days I finally found the problem.
First, let me say that I did try too to create a network
docker network create mynet
and used the tag docker run --network=mynet in both mysql-container and karaf-container.
In my hook, I did try to replace localhost with mysql-container:3306 and even after that it didn't work.
Anyway, to resolve, I did what I said above, plus create a new super user:
docker exec -it mysql-container mysql -u root -p
CREATE USER 'user'#'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'%';
FLUSH PRIVILEGES;
And after that, all worked fine.
I will leave here a usefull link that was kinda hard to find but it has pretty good info:
https://codebeamer.com/cb/wiki/5854748
plus, for the 2 extra questions I asked:
1- Still didnt find the kube dashboard, didn't look much for it yet to be honest.
2- For what I have seen in the build.sh it will search a specific folder name 'apache-karaf', so I think this error here happens if you rename your folder and it doesnt match with the build.sh.

How do I get Lando mysql portforward to work with lamp recipe

[This isn't directly about docker, but I couldn't add lando as a tag.]
Every time I stop and restart my Lando app, the external mysql port changes. This is because the database in the lamp recipe is set to portforward rather than to a specific port. I want a consistent port so that I don't have to keep change host phpMyAdmin config.inc.php file every time I reboot my computer.
Here's my current .lando.yml:
name: test
recipe: lamp
config:
webroot: www
php: 7.2
conf:
php: config/php/php.ini
db:
portforward: 32792
The portforward setting doesn't work: I still get a new external mysql port on rebuild. I've tried various alternatives to no avail.
Any ideas on how to correct the above?
I found an answer on the Lando slack channel. I needed to change
db:
portforward: 32792
to
services:
database:
portforward: 32792
where services aligns fully on the left and is not an entry under config.

Automatically Start Multiple MySQL instances on boot in Ubuntu Trusty 14.04

I'm still learning how to use Linux & MySQL, so please keep answers simple :)
I've been following this tutorial :
http://www.ducea.com/2009/01/19/running-multiple-instances-of-mysql-on-the-same-machine/
Both MySQL instances (the default instance you get on installing MySQL and the new one I created in the aforementioned tutorial) are working correctly.
But, when I boot up my OS, only the first (default instance) starts up, so I have to manually start the second instance.
I've been doing this by running these commands as root:
Start the instance:
mysqld_safe --defaults-file=/etc/mysql2/my.cnf &
Connect:
mysql -h 127.0.0.1 -P 3307
How do I make it so that both of these instances will start at boot time?
Thanks!
I fixed it by simply running the command at startup by using the solution in this question :
Ubuntu - Run command on start-up with "sudo"
Steps I took :
I added this command to the "/etc/rc.local" file as root:
(Before the "exit 0:" line or it will never get executed)
sudo mysqld_safe --defaults-file=/etc/mysql2/my.cnf &
Then I restarted my OS. The new instance is now automatically started :), so now I have both starting on boot!
Though now i wonder.. is this the correct way to handle this issue?