XAMPP

Description

XAMPP is a software distribution which provides the Apache web server, MySQL database (actually MariaDB), Php and Perl (as command-line executables and Apache modules) all in one package. It is available for Windows, MAC and Linux systems. No configuration is necessary to integrate Php with MySQL.

It is a great fit for this course and provides a relatively painless installation and way to manage the configuration changes. Also provided is PhpMyadmin which gives a GUI tool for managing your MySQL databases.

I would highly recommend installing this for Windows or MAC. It doesn't exclude you from other competing software installations, it just gives an easy way to get going. For Ubuntu Linux systems, I still would recommend installing Apache/MySQL/Php/PhpMyadmin through Ubuntu packages.

The XAMPP download site which I use is:
https://www.apachefriends.org/
The installation I'm describing uses Php 7.

Windows

The installation file I used is:
xampp-win32-7.0.13-1-VC14-installer.exe
Install in the usual way. It gives some notification messages for which you can just click OK. Close whatever installation brings upon completion. It installs into
C:\xampp
At some point the Windows Firewall may invoke notifications; just click Allow access and then Finish.

Run XAMPP Control Panel as administrator

What you want to run is the XAMPP Control Panel found under XAMPP in the Start menu. Right-click and run this as administrator.

Start both MySQL and Apache (unless you have an alternative Apache installation). I do not recommend messing with the Modules service column. When you start MySQL, you should see it running on port 3306. The Apache service gives you access to the Admin buttons next to the services. For Apache Admin, you get:
http://localhost/dashboard
For MySQL Admin you get PhpMyadmin:
http://localhost/phpmyadmin

The MySQL clients

The MySQL Client executables are located in the directory
C:\xampp\mysql\bin
The most important one is the client program mysql.exe. From a command shell you can run:
> C:\xampp\mysql\bin\mysql    (with or without the .exe extension)
MariaDB[(none)]>
MariaDB[(none)]> quit
This accesses the MariaDB database as the empty (or default) user with empty password. You can go into a specific database, say test, by doing:
mysql> use test
MariaDB[(test)]>
This test database already exists in the XAMPP MariaDB installation. It is accessible by the empty user. You can also go directly into the test database from the command line by:
> C:\xampp\mysql\bin\mysql test
MariaDB[(test)]>
You can also go in as an unknown user, e.g.:
> C:\xampp\mysql\bin\mysql -u guest test
What's happening here is that the unknown user is getting replaced by the empty user.

If you want to create other databases, or users, or alter passwords, you have to be the root user. To do so:
> C:\xampp\mysql\bin\mysql -u root
The XAMPP installation also sets up the empty password to the root user.

Easy access to mysql

Although it is probably OK to use mysql as:
C:\xampp\mysql\bin\mysql
You might want to make it usable simply as mysql. Here are two ways to do so.
  1. The best solution is to put the directory into your PATH. Start from Control Panel ⇾ System and Security and access:
    System ⇾ Advanced System Settings ⇾ Advanced ⇾ Environment Variables
    Find the Path variable in the System Variables. Select it and click Edit. It's best to prepend the new Path component with this addition:
    C:\xampp\mysql\bin;
    
    The Home button on a Microsoft keyboard is a good way to get to the beginning of the Path expression. Alternatively, you can append the new Path component as:
    ;C:\xampp\mysql\bin
    
    Then "OK" your way out.
  2. Another way is to make a convenience batch executable in the directory where your shell opens up into (it should be your home directory). Go to your home directory C:\Users\YOUR_LOGIN (or wherever your shell opens into) and create the file
    mysql.bat
    
    Make sure file extensions are shown. Create an empty text file (New Text Document.txt) and rename the whole file to mysql.bat (Windows will complain!). Make the contents be:
    @echo off
    C:\xampp\mysql\bin\mysql %*
    
With either of these in place, start a new command shell and test it by running
> mysql

Other mysql accesses

Run the actual command client program through a command shell (cmd) by simply using mysql with various arguments. For example, try each of these (quit to leave MySQL):
> mysql                      as anonymous user
> mysql -u root              as root user
> mysql -u root mysql        as root user into mysql database
> mysql test                 as anonymous user into test database
> mysql -u guest test        as guest user into test database
> mysql mysql                as anonymous user into mysql database (fails)
> mysql -u guest mysql       as guest user into mysql database (fails)

Using Cygwin MySQL Client executable

If, like me, you prefer the Cygwin shell, you can still get access to the XAMPP MySQL database through the Cygwin mysql client. Install the mysql client package in Cygwin, but don't install the mysql server package. Then you will be able to access the XAMPP (or any other) MySQL database with an added option like this:
$ mysql --protocol TCP ...
To simplify this usage, create an alias by adding this line to your ~/.bashrc file:
alias mysql='mysql --protocol TCP'
Open a new Cygwin shell and my can now use the mysql client directly.

MAC

The installation file I used is
xampp-osx-7.0.13-1-installer.dmg
Install in the usual way. The installation location is
/Applications/XAMPP
and all executables are in
/Applications/XAMPP/bin
Starting /Applications/XAMPP will automatically start the Control Panel and you'll need to give your password so that the application can run as root and start services on protected ports.

Use the Manage Servers tab in the Control Panel to start up MySQL (on port 3306) and/or Apache (on ports 80,443). Initially we only need MySQL.

There doesn't appear to be any automatic way to invoke the "dashboard" and "phpmyadmin" URLs, but these are still available when both MySQL and Apache are running.
http://localhost/dashboard
http://localhost/phpmyadmin

Access to the XAMPP Client Executables

The most important executable at this point is the mysql client, which is the file:
/Applications/XAMPP/bin/mysql
You should be able to execute this as is, but the best way is to execute it (as well as other XAMPP executables) is to augment the system PATH. To do so, edit the bash shell startup file:
~/.profile
The simplest way to edit it might be:
$ nano ~/.profile
Add the one line into the file to augument the PATH:

~/.profile
PATH=/Applications/XAMPP/bin:$PATH
Be careful to have no spaces around the equals sign!

Then start up another terminal shell. Test the effectiveness of what you've done by typing this in the shell:
$ echo $PATH
$ which mysql
You should see the /Applications/XAMPP/bin component as the first component in the PATH variable.

Using the MySQL Client executable from another installation

Any installed MySQL client can access the XAMPP MySQL database in the same way as in the Cygwin subsection of Windows:
$ mysql --protocol TCP
If you need to do it this way, do so using an alias as suggested above.

Testing mysql

Run the test programs from the Windows section.


© Robert M. Kline