Start mysql and apache from cmd - mysql

I installed xampp and now I want start apache and mysql from command line and also I won't install services.
I use some command and it's worked but after start mysql (for example) cmd is open, I want close but after close cmd mysql stopped.

You can't. Either you run it from the command line, having to keep the shell open, or you run it as a service after which you can close cmd (if you used cmd at all).
I would choose the latter, and I can't understand why you won't install it as a service.

If you are using XAMPP, you can start your servers by doing:
sudo /opt/lampp/lampp start
Otherwise, you can start your servers with this one:
sudo service apache2 start && sudo service mysql start

Related

MAMP server : start and stop server [duplicate]

I am trying to find a way by which I can start and stop MAMP PRO's Apache and mysql using command line.
So far whatever I have search has only helped me start MAMP PRO.
Thanks.
As of at least MAMP 3.0.6, the following works for both Free and Pro versions:
Open MAMP Pro or Free, depending on the one you use:
Pro:
open /Applications/MAMP\ PRO/MAMP\ PRO.app/
Free:
open /Applications/MAMP/MAMP.app/
Then, cd into MAMP/bin:
cd /Applications/MAMP/bin
To start Apache & MySQL:
./start.sh
To stop Apache & MySQL:
./stop.sh
Note that you might need to sudo the commands above.
After much trial and error:
Note that I have my ports set to the application's respective defaults (Apache: 80, MySQL: 3306), and as such these commands reflect that, AND you must use sudo with Apache (which you will in MAMP as well if you're using port 80).
Apache
sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k start
sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k stop
sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k restart
MySQL
To start MySQL:
sh -c '/Applications/MAMP/Library/bin/mysqld_safe --defaults-file=/Applications/MAMP/tmp/mysql/my.cnf --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --user=alex --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log.err --tmpdir=/Applications/MAMP/tmp/mysql/tmpdir --datadir=/Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql &'
(for some reason you must hit enter again to regain your prompt)
To stop MySQL:
sh -c '/Applications/MAMP/Library/bin/mysqladmin -u root -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown'
As a bonus, the indicators in the MAMP PRO.app GUI show the correct status of these apps in real time, so you can continue to rely on that.
I have MAMP PRO v2.0.3.
http://pastebin.com/avn0BFap
Save the script and give executable rights such as: chmod +x start.sh
Then use it like ./start.sh Start or ./start.sh Stop or ./start.sh Restart
Best Solution for MAMP 3 on OSX
(should work for MAMP Pro as well).
Look inside of the folder:
/Applications/MAMP/Library/bin
You'll see the scripts used for starting and stoping Apache & MySQL.
Look inside any of the scripts:
start.sh or stop.sh or startApache.sh etc
You will see that they use the program:
apachectl
You can use the restart command with apachectl. So, just set-up an alias in your ~/.bash_rc file:
alias rap='sudo /Applications/MAMP/Library/bin/apachectl restart'
rap is the acronym I gave for 'Restart Apache'. Presto! One step from the command line without having to open the MAMP application. Use the same logic if you want to set this up for MySQL.
To start it on MAMP pro version 4 it's
/Applications/MAMP\ PRO/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
To stop it it's
/Applications/MAMP\ PRO/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
Sadly
Based on the advice given here
"https://deliciousbrains.com/automating-local-wordpress-site-setup-scripts-part-3-automating-rest"
And found then discovered - it's HIDDEN in the documentation right here.
https://documentation.mamp.info/en/MAMP-PRO-Mac/How-Tos/General/CreateHostDatabaseCommandLine
Nearly the same with MAMP Pro 5:
/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
start:
/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
If you are using MAMP PRO there is an easier way to stop MySQL.
MAMP PRO creates a shell script in your Library folder. If you've changed the password for the root user (which you should), the updated password will also be reflected in the script. The file can be found at:
~/Library/Application Support/appsolute/MAMP PRO/stopMysql.sh
In order to type that on the command line you need to escape the spaces by adding a backslash in front of them like the command below.
Stop MySQL Shell Script for MAMP PRO
~/Library/Application\ Support/appsolute/MAMP\ PRO/stopMysql.sh
The other thing that I found on my system was that the file didn't have the execute bit set on it. I cheated and used Path Finder to set the file as executable but you can easily find information about how to do it through the command line with chmod.
Unfortunately I can't find a proper start script created by MAMP PRO. I wanted to find something simple to use for the start command in MySQLWorkbench but for now I just left it blank because the default MAMP script does not work. I may create a script based on the helpful commands Astockwell posted in response to this question.
I found /Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup, which works for me in MAMP PRO, with custom ports.
Just run
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup start
or
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup stop
etc.
Simple way would be to shut down and restart the application, MAMP PRO will start and stop Apache and MySQL.
start MAMP PRO
open -a MAMP\ PRO
stop MAMP PRO
osascript -e 'quit app "MAMP PRO"'
For MAMP Pro 5 use
sudo /Applications/MAMP/Library/bin/apachectl -f"/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k restart
remember, you must use sudo
For MAMP5.5, search for this script file in your MAMP bin folder: startMysql.sh
It would have few lines:
#!/bin/sh
/Applications/MAMP/Library/bin/mysqld_safe --port=8889
--socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log &
Copy Paste the entire command on your OSX shell and just press enter, your Mysql server would start.
Open a new shell and start using Mysql from command line.

Unable to stop MySQL on OS X 10.10

I'm starting to go nuts over this.
I setup MySQL/Apache/PHP using the tutorial by Coolest Guides On The Planet.
I'm guessing something went wrong as its not working as expected so I want to uninstall and try again.
The trouble is that I can't stop MySQL either by system preferences or command line. I keep trying suggestions on the net but so far unsuccessful.
Can anyone help?
Finally got around the autostart - Thanks to all who contributed and allowed me to see the way.
To stop the auto start I used:
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist
And to kill the service I used:
sudo pkill mysqld
This is what worked for me. It was listed under a different plist name:
sudo launchctl unload -w com.oracle.oss.mysql.mysqld.plist
For Mac Users
kill -9 {pid} kept restarting the process. This was because I had MySQL Server running. On OSX I had to:
1- System Preferences.
2- Search for mysql.
3- Press the Stop MySQL Server button.
got it from a github issue, and it solved my problem
https://github.com/docker/compose/issues/4950#issuecomment-407145733
brew services stop mysql#5.6 worked for me, when all else failed.
I also got the same problem, unable to stop MySql Sever through system preferences on macOS High Sierra.
I did brew uninstall mysql on my terminal window.
now I am able stop stop MySql Sever through system preferences.
Since mysql was installed on my mac 2 ways binary as well as home brew.
in terminal
kill `pgrep mysqld`
this kills the mysqld process.
If you used brew then you can find out which version you are using by:
launchctl list|grep mysql
this will print something like
92555 0 homebrew.mxcl.mysql#5.7
In my case I'm using mysql#5.7
You can stop using:
brew services stop mysql#5.7
Try with issuing the following command in command line:
ps -xo pid,ppid,stat,command | grep mysqld
It will show you your processes, with their parent ID in the second column. Look for the mysqld and it's parent process. After locating it, issue a:
sudo kill pid
where pid is mysqld's parent process ID.
EDIT
If you want to stop the process from launching again, try:
sudo launchctl unload /System/Library/LaunchDaemons/mysqld.plist
I've installed mysql via homebrew, but stop mysql by using mysql stop command, mysql restart right now.
try to execute command as follow if your mysql was installed via homebrew
brew services stop $(brew list | grep mysql)

mysql won't start for xampp for mac users

======
Mysql cannot start, i am thinking maybe it was conflict with other mysql i have install in my computer.
How to properly config mysql?
I have tried to kill the mysql task, or sudo start it in my terminal
The following steps worked for me, assuming you are using Yosemite:
Step 1.
Delete \Applications\Xampp
Step 2.
Delete usr\local\var\mysql folder
Step 3.
Reinstall Xampp 5.5.19.
Step 4. Run the following commands in terminal to kill the processes, then restart the servers in Xampp.
sudo killall httpd
sudo killall mysqld

start apache & mysql from desktop script in ubuntu

on lubuntu 14.04 (desktop) i have installed apache web server and mysql server and, because of low ram (only 1024mb), i decided to remove them from startup (with sudo update-rc.d -f apache2 remove and by editing the /etc/mysql/my.cnf file ).
now, every time i want to do some development i have to sudo service apache2 start and sudo service mysql start in a terminal. wich is fine.
my question is: could those commands be executed from a .sh file? a file that i can double-click it from my desktop?
so far i got
#!/bin/sh
sudo service apache2 start
sudo service mysql start
You can do it with scripts which you mentioned.
Apache:
#!/bin/sh
sudo service apache2 start
Mysql
#!/bin/sh
sudo service mysql start

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

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