php5-msql installed on Ubuntu but not shown in phpinfo.php - mysql

I am setting up Nginx+PHP+MYSQL on Ubuntu 12.04.
I used
apt-get install php5-mysql
to install MySql module for PHP. However, everything seems to be installed and enabled, it is yet shown in phpinfo.php and I cant get the php application to connect to the MySql server. The php app is accessible, and I can view things on phpinfo.php.
BTW, mysql is running normally, because I am running an Rails app using it, so I know it is working fine.

As #vstm said a quick summary to help others get the answer quicker:
1. Kill php-cgi
killall php-cgi
2. Restart php-fpm
/etc/init.d/php5-fpm restart OR service php5-fpm restart
3. Double check with
grep -E 'extension=(pdo_)?mysql.so' -r /etc/php5

Related

How to install and start MySQL 5.7 on macOS BigSur (Apple Silicon) with Homebrew?

I need a specific version of MySQL (5.7) to be installed on my MacBook with M1.
I'm trying to do that with Homebrew.
brew install mysql#5.7
The output:
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
mysql#5.7 is keg-only, which means it was not symlinked into /opt/homebrew, because this is an alternate version of another formula.
If you need to have mysql#5.7 first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql#5.7 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/mysql#5.7/lib" export CPPFLAGS="-I/opt/homebrew/opt/mysql#5.7/include"
To have launchd start mysql#5.7 now and restart at login: brew services start mysql#5.7 Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql#5.7/bin/mysql.server start
Right after that, I try to run:
echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
source .zshrc
mysql_secure_installation
And get the error:
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Also, I've tried:
brew services start mysql#5.7
And also get the error:
Error: Permission denied # rb_sysopen - /Users/vivanc/Library/LaunchAgents/homebrew.mxcl.mysql#5.7.plist
Seems like there is a permissions-related problem.
Any advice is appreciated.
If you are running into issues like "Can't connect to local MySQL server through socket '/tmp/mysql.sock'" or "The post-install step did not complete successfully MySQL", and you installed a previous version of mysql (e.g. 8.x) previously, you may have been at the point where you need to clean everything before reinstalling your preferred version of mysql#x.x.
If you've already visited these to links:
Uninstall all those broken versions of MySQL and re-install it with Brew on Mac Mavericks (Coderwall) + Install MySQL 5.7 on macOS using Homebrew (github) and your're still having trouble with starting your mysql-service, you should try to also remove also /opt/homebrew/etc/my.cnf file.
Remove it together with all the related files too! Summary for an M1 Apple Silcion machine, after uninstalling via brew uninstall mysql or brew uninstall mysql#x.x, please remove:
/opt/homebrew/var/mysql
/opt/homebrew/etc/my.cnf
After this, everything worked like a fresh install (for me). Hope this saved someone's time.
While this question is specific to Apple Silicon and mysql 5.7, and I will address that in this answer, I would like to start by adding some general notes to save others time:
Homebrew supports mysql 5.7 for both intel and apple silicon.
https://formulae.brew.sh/formula/mysql#5.7
Homebrew supports mysql 5.6 for the intel chip, but not apple silicon:
https://formulae.brew.sh/formula/mysql#5.6
If you need 5.6 on apple silicon, it's probably a good idea to just settle with 5.7 since production will need to be upgraded eventually and the differences aren't that big.
In my situation I originally did brew install mysql and it gave me the latest mysql (currently 8.0). When I tried going back over it and doing brew install mysql#5.6, of course this didn't work due to not being supported on the m1 max (apple silicon). I ran into issues then trying to get brew install mysql#5.7 working. I followed some guides mentioning various suggestions. After playing with it for a while, it seems that running two versions of mysql at once will corrupt your mysql files and make it hard to work with and confuse homebrew.
I came across these guides:
brew install mysql on macOS
https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks
https://www.codegrepper.com/code-examples/shell/brew+uninstall+mysql
Before reading further, note that in my situation, I had a zip available for my whole local mysql database needs and could risk destroying what I have.
Warning! Reading further and executing these commands carelessly may delete your mysql storage. Make sure you have a backup.
brew remove mysql is a good command that got rid of my latest install.
I also needed brew remove mysql#5.7 even though this is the version I'm trying to install, but they were stepping on each other's foot...
brew cleanup is nice, I noticed it freed up some lock files.
I don't recall having any luck with:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
but you can try it.
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist has worked for me.
But note there will also be another file in there for your 5.7 setup.
I'd recommend:
cd ~/Library/LaunchAgents/ then look around to see if you have any mysql* in there. Then if you do, such as homebrew.mxcl.mysql#5.7.plist, then remove it.
These are some that worked for me:
sudo rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf
rm /usr/local/etc/my.cnf.default
Also:
cd opt/homebrew/var
Then if you notice a mysql directory in there, remove it.
It's possible you might have docker or something else similar also running mysql or mysqld.
ps -ax | grep "[m]ysql"
(Note the brackets and quotes in the above is to prevent the grep from showing up in the process list and matching itself unlike the lazier version: ps -ax | grep mysql which will give the impression there's an extra mysql process running)
Once you're ready, please run:
brew services list
double-check you don't have mysql in there.
Then double check you don't have any mysql process running:
ps -ax | grep "[m]ysql"
This can happen for example if you enter mysqld for example....
You might need to do brew services stop mysql or brew services stop mysql#5.7 or similar and repeat steps if you see anything on the service list or process list.
Finally, you should be ready for a fresh install.
The fresh installation process should be rather straight forward:
brew install mysql#5.7
brew link --force mysql#5.7
brew services start mysql#5.7
Then run brew services list to make sure your installation worked correctly.
If you see it's green and "started", your installation was successful!
You should also run:
mysql_secure_installation
Then choose a password for root and go through the list of questions like validation, etc.
Once you're installed, you might also run into mysql mode issues.
cd /opt/homebrew/etc and you should find a my.cnf file.
Edit it using either vim or nano.
You should see something like:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
Edit it and set the mysql mode. For example, I don't want the no_zero_in_date mode, so I use:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Then restart mysql like so:
brew services restart mysql#5.7
Then double check you still have a green status "started":
brew services list
If you do, then you should have the no_zero_in_date mode disabled.
You can test it with a query:
SELECT ##sql_mode;
You should now have mysql 5.7 running on Apple Silicon and have the sql_mode set.
If you run into more troubleshooting, do your best to get into a known state such as uninstalled, doing a fresh install, or already installed with some version, etc.
I solved it after hours of searching, it was because I had not cleaned everything regarding my previous MySQL 8.X installation. I followed this and got suspicious when I realized I don't have most of the folders there. I then did a search for all folders named mysql on my computer and found a mysql folder in opt/homebrew/var. After removing it, reinstalling MySQL 5.7, and starting the server everything is working as expected.
When setting up my Apple M1 Macbook Pro I was experiencing the issue of the following error message being thrown:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
My fix was to modify the MySQL config file:
nano /usr/local/etc/my.cnf
Append the following lines:
tmpdir=/tmp
user=root
Then run:
brew services restart mysql#5.7
This fixed my issue, and I was then able to connect successfully with my DB client.
Seems like I found the solution (or workaround).
After installing the MySQL 5.7 with Homebrew just run:
mysql.server start
MySQL is started and then you are able to run mysql_secure_installation and mysql commands.
I got this warning:
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
And make sure that your user has write permission.
chmod u+w /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
I run those two command then it works.

How can I connect to MySQL from Perl?

I am trying to create a login page for a website using perl CGI. In an already existing script the database handle is connect("DBI:mysql")
When I run the command
$ mysql -u root -p
The linux server shows command not found.
I am new to modules DBI and CGI in perl. So i am confused if mysql does not exist on the linux how should i create a database and connect to it using DBI?
There could well be many steps to get through here in order to get this all working.
But, question one is: which platform are you running on? Your command prompt makes me think it's Linux, but which distribution and which version of that distribution.
It looks very much like you don't have the MySQL client packages installed. The easiest way to do that will depend on your answer to question one.
On a Debian-based system (which includes Ubuntu), you can run:
$ sudo apt-get install mysql-client
On a RedHat-based system (which includes things like Fedora and Centos), you can run:
$ sudo yum install mysql-client
If that last command tells you that yum can't be found, then try:
$ sudo dnf install mysql-client
Once you have the client installed, we can move on to the next step :-)

Remove one of two instances of mysql - Linux

I am total newbie on Linux. Yesterday I installed XAMPP and it throw me an error about busy port 3306. As I found out I have some mysql servel running in folder /usr/sbin/mysqld. I don't know how is it possible, but I would like to remove that. How can I do it and don't damage xampps mysql? THX.
Os: Linux - Mint
run this command :
sudo apt-get remove mysql-server mysql-client mysql-common
that will remove all mysql data in /usr/sbin/mysqld, but not remove anything in your mysq data XAMPP
echo manual | sudo tee /etc/init/mysql.override
MySQL runs from an upstart file, which can be disabled with an override file. This will disable it permanently, and the service will have to be enabled manually. If you would like to run the service on startup again, simply delete the override file.

Your PHP installation appears to be missing the MySQL extension which is required by WordPress. On Ubuntu 14.04 LTS

Your PHP installation appears to be missing the MySQL extension which is required by WordPress
I tried to fix this problem by making sure MySQL server is running.
/etc/init.d/mysql status
I found it is running properly.
Then I cheked for MySQL Module for php5 is installed
dpkg --list | grep php5-mysql
and finally, I restarted the NGINX:
/etc/init.d/apache2 restart
Still facing the same issue again and again:
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
Thanks for contributing to the answer.
Nothing worked to solve this issue. Although I faced the same issue. #igor yavych answer was quite useful.
Finally R&D worked and here's the final solution:
In order to deploy PHP applications, you will need to implement the following “PHP-FastCGI” solution to allow nginx to properly handle and serve pages that contain PHP code.
sudo apt-get install php5-cli php5-cgi php5-fpm
Now, install NGINX:
sudo apt-get install nginx
Now configure NGINX then restart NGINX and PHP5-fpm:
service php5-fpm restart
/etc/init.d/nginx restart
Issue the following command to install the MySQL server packages and required PHP support for MySQL (You do not have to purge MySQL Server):
sudo apt-get install mysql-server php5-mysql
Finally restart php5-fpm:
service php5-fpm restart
Congratulations! Now it's working!
You can also check my step-by-step guide.
This is error that means that your PHP either has mysql/mysqli extension disabled or doesn't have it to begin with. If said extension is actually present, check your php.ini and your additional configuration files to see if it's actually enabled (for example extension=/path/to/extension/mysql.so). You can also check phpinfo to see what's actually there.
Fixing this problem was quite simple. All I had to do is go into my nginx server block like so:
sudo nano /etc/nginx/sites-available/myblog.com
then in the server block all I had to do is find
php7.0
and change it to
php7.2
Basically, with the upgrade of Ubunto 17.04 to 17.10 php7.0 was no longer working but I still had php7.0.
this is where you will find it in your server block:
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
So, from now on just remember to update your nginx server blocks after an upgrade of Ubuntu or PHP. There is no need to mess with the shell or other configurations any further.

MySQL Mac OS X Problems

something strange is happening while trying to run MySQL server on my MacBook Air.
First ill installed MySQL using brew install mysql. Installation was successful without any errors.
And then problems started to showing up...
First i had to use following command in order to create empty tables:
cd /usr/local
sudo mysql_install_db --user=mysql --ldata=/var/db/mysql
Now im trying to launch the server service itself, but another error is not allowing me to do it:
ivankutsarov$ sudo mysql.server start
Password:
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/Ivans-MacBook-Air.local.pid).
While ill navigate to the mentioned folder i cant see mysql folder in it, neither i can see it in my /usr/local/bin directory.
Any ideas guys?
Guys i found the problem. I forgot to run these 2 commands after installing mysql:
First, run: brew help mysql
Read the info displayed after command was executed, and you will notice in the first 2 lines the following commands which are necessary to run in order to start your server!
1.
unset TMPDIR
2.
mysql_install_db --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
I had a similar problem a day ago. mysql functioned fine until out of the blue PID file errors occur. I tried everything to fix the installation, replacing a dozen of files and trying many different settings.
what eventually worked was a clean install of mysql via the dmg package and a migration of my data&schema's to this install (use mysql workbench for this to save time), then uninstalled the version installed via brew.
https://dev.mysql.com/downloads/file/?id=466265