What command does XAMPP use to start MySQL? - mysql

To start a MySQL (technically mariadb) module from the XAMPP control panel, you just click the "Start" action button. What command is being run behind the scenes for "Start"? I've tried to replicate it from the command line with a variety of commands, but I've found that the "Start" button will succeed where my command-line commands fail.

The net start and net stop commands from a command line will start and stop services including of course MySQL or MariaDB.
net start mariadb

basically
mysqld.exe --defaults-file="C:\ammpp\my.ini"
mysqld is the server command
the my.ini ist the configuration you have to check the folder
And MySQL80 is the name
see manual for more options
As the github says is the command line in the batch file xampp/mysql_start.bat `
mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone --console
the my.ini makes some minor changes to the default values, no trickery at all

I have no idea what trickery the XAMPP package uses, but if you want to start the mariadb service from the cmd, all you need is an elevated command prompt and the following line:
net start MariaDB
Note: my OS is Win10

A modification of nbk's answer worked for me in PowerShell:
C:\xampp\mysql\bin\mysqld.exe --defaults-file="C:\xampp\mysql\bin\my.ini" --console
This shows up as running in the XAMPP Control Panel (v3.2.4) and uses the correct port from the my.ini file (I'm using port 3308).
To stop the MySQL server, you can hit Ctrl+C, but only if the MySQL server is open with the --console param. To stop it from another terminal I've tried various shutdown commands, but none have worked for me so I've had to use the ugly command:
taskkill /FI "IMAGENAME eq mysqld.exe" /T /F
From a .bat batch file I've also found these commands useful for starting and stopping:
:: Start
start "XamppMySQLD1" powershell -NoExit -command "& 'C:\xampp\mysql\bin\mysqld.exe' --defaults-file='C:\xampp\mysql\bin\my.ini' --console" || echo ERROR && exit /b
:: Is it running? On the expected port?
tasklist | findstr /i "mysql"
netstat -ano | findstr 3308
:: Stop
taskkill /FI "WindowTitle eq XamppMySQLD*" /T /F

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.

How to stop XAMPP's MySQL Service after updating MariaDB

I've updated my MariaDB to version 10.3.14 using this steps (link)
It has been successfully installed, but when I tried to stop the MySQL Service from XAMPP Control Panel, it won't stop.
The status always shows like this:
[mysql] Attempting to stop MySQL app...
Like the picture below:
How can I stop that?
You can kill the process operating on port 3306.
Type in CMD (Command Prompt) if you have windows:
netstat -ano | findstr :<yourPortNumber>
put your port number in the diamond brackets.
then put the process ID in diamond brackets,
taskkill /PID <typeyourPIDhere> /F
I also had this issue so for anyone looking for an answer to fix the panel rather than using taskkill from cmd here is why this is happening:
The XAMPP Control panel you have installed is 32bit, while upgrading your MariaDB by following this method you downloaded the 64bit MariaDb version. That is why the XAMPP panel will not stop the MySQL process.
Download the 32bit version of MariaDB and re-do the installation process and it should be all sorted.
Open up cmd.exe(PORT= your port number)
Step 1
netstat -ano | findstr :<PORT>
Step 2
taskkill /PID <PID> /F

add services to init.d on Ubuntu

I'm trying to simplify commands on my ubuntu server.
For now, to start / stop / restart apache2, we have to type those commands :
stop : /etc/apache2/bin/apachectl -k stop
start : /etc/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.conf
restart : /etc/apache2/bin/apachectl restart
and kinda same for MySql :
stop : mysqladmin -u root shutdown
start : mysqld_safe --user=mysql --log &
What I wish is to be able to use /etc/init.d/apache2 start or /etc/init.d/mysql start to make it simple and not having to always look at the Wiki to find the exact command to use each time...
I tried to find samples of files to put in init.d folder, but found nothing.
I also wanted to know how to do the same with service apache2 start (and same for stop/restart and MySql).
Is there a difference between using /etc/init.d/xx start and service xx start ?
Thanks for you help !
Just put the executable file i.e apachectl in /etc/init.d/ and than try with /etc/init.d/apache{tab} restart/start/stop and all for mysql too it will work.
Actually init.d contains the shell script file that is executable.
Take care the file should be executable like below
chmod +x /etc/init.d/apachectl

Execute Multiple Command Using Batch File and install MySQL using batch file

I'm trying it write a window batch file to perform several tasks in series, However, it always stops after tie first command in the script.
I am use this this batch file code:
start cmd /k cd %CD%mysql\bin && mysqld --install
I want to use this batch file command and install the MySQL but it run only only one command
You have the following command in your batch file:
start cmd /k cd %CD%mysql\bin && mysqld --install
Lets break it down into smaller pieces.
start start a program, command or batch script (opens in a new window.)
cmd /k cd %CD%mysql\bin run `cd %CD%mysql\bin and then return to the cmd prompt.
&& if the above succeeds then run the next command
mysqld --install run mysqld --install if start cmd /k cd %CD%mysql\bin succeeded
The second part will never run as the first part returned to the command prompt.
Try the following batch file instead:
cd %CD%mysql\bin
mysqld --install
Note the variable CD must be assigned a sensible value, otherwise cd %CD%mysql\bin will fail.
Seems you have a lot of layers here: both start and cmd /c (which I think you'd prefer over cmd /k for use in a batch file).
What's wrong with just cd %CD%\mysql\bin && mysqld --install? This worked fine for me when I attempted to run notepad.exe thus: cd /d %WINDIR%\System32 && notepad (note the additional '\' character here, just in case ... an extra backslash won't hurt if env var CD already has one). For that matter, I'll bet %CD%\mysql\bin\mysqld --install would work just fine.
However, just in case you want the extra cruft – or, more likely, need it for some other functionality you're not showing. Using just cmd:
cmd /c "cd %CD%\mysql\bin && mysqld --install"
using just start:
start "" "cd %CD%\mysql\bin && mysqld --install"
I'd put a solution using both start and cmd, but you just don't need it.
BTW, if you can't just call %CD%\mysql\bin\mysqld --install directly, I'd look into using pushd instead of cd, so that you can call popd at the end of your overall script ... it's just good form to put your script user back in the directory in which they started.

How can I access the mysql command line tool when using XAMPP in OS X?

I've got a vanilla install of XAMPP in OS X. How can I access the mysql command line tool? I've tried typing "mysql" at the command line, and it spits back "-bash: mysql: command not found".
XAMPP is installed in Mac OS X in the following directory:
/Applications/XAMPP/
You can look what's inside that directory and run mysql command line tool providing the full path to it:
$ /Applications/XAMPP/xamppfiles/bin/mysql
If you need, you can modify your PATH environment variable to include XAMPP binaries and you won't need to specify the whole path all the time.
Open your .profile file in Mac. This can be done by entering the terminal and typing
pico ~/.profile
Add the following line to your ./profile file. Replace the path where you installed Xampp, however by default this is the route and should work:
export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH
Open a new terminal window (Recommendation is to quit all terminal windows and then reopen) and type:
mysql
That is all, isn't easy!!
Before using the mysql command, make sure that you start up the server first by running
$ mysql.server start
Then you will be able to use the commands mysqladmin and mysql.
To shut it down, run
$ mysql.server stop
and to restart just use
$ mysql.server restart
Very intuitive.
Open terminal and Follow this bellow step to add mysql to your mac environmental variable
step 1:
sudo nano ~/.bash_profile
step 2:
export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH
save it by control+x and then y and hit return. That's it!! now close the terminal and reopen
mysql --version
this will tell you which MySQL version you are using with xampp
Since I cannot comment on the accepted answer by Pablo Santa Cruz - Here's some additional info. If you're going to modify your PATH environment variable to include XAMPP binaries, make sure you add
/Applications/XAMPP/xamppfiles/bin
and not
/Applications/XAMPP/xamppfiles/bin/mysql
to the /etc/paths file. To do this run the command
sudo nano /etc/paths
then add the path to the file. Save using Ctrl+O and exit using Ctrl+X. Quit terminal and open again.