MYSQL Create databases

Pre-Flight Check
  • These instructions are intended for creating a MySQL database on Linux via the command line.
  • I’ll be working from a Liquid Web Core Managed CentOS 6.5 server, and I’ll be logged in as root.
Create a MySQL Database

First we’ll login to the MySQL server from the command line with the following command:

mysql -u root -p

In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.

If you need to change your root (or any other) password in the database, then follow this tutorial on changing a password for MySQL via the command line.

You should now be at a MySQL prompt that looks very similar to this:

mysql>

To create a database with the name tutorial_database type the following command:

CREATE DATABASE tutorial_database;

If a database of the same name already exists, then a new database will not be created and you’ll receive this error:

ERROR 1007 (HY000): Can't create database 'tutorial_database'; database exists

To avoid seeing this error use the following command instead:

CREATE DATABASE IF NOT EXISTS tutorial_database;

The above command will only create the database tutorial_database if a database of that name does not already exist.

View All MySQL Databases

To view the database you’ve created simply issue the following command:

SHOW DATABASES;

Your result should be similar to this:

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| tutorial_database  |
+--------------------+
4 rows in set (0.00 sec)

FreeBSD 10 FAMP

FAMP – Installing Apache2.4, MySQL, PHP on FreeBSD 10

Here is a procedure to install a FAMP(FreeBSD with Apache, MySQL and PHP) server. The following setup runs Apache 2.4, MySQL 5.6, and PHP 5.5 on FreeBSD 10. If any version of the packages needs to be changed, replace the versions in the commands accordingly.

Pre-Installation Tasks

Before installation of the components, Download the compressed snapshot of the ports collection, using the following command

# portsnap fetch

Now extract the snapshot into /usr/ports using the following command

# portsnap extract

Apache 2.4 – Installation and Configuration

# cd /usr/ports/www/apache24
# make install

(While running “make install” the installer asks to check the boxes to install various libraries and support packages. Check the appropriate boxes as per requirements.

# make clean

Edit the apache configuration file i.e. /usr/local/etc/apache24/httpd.conf and make the following changes

ServerRoot "/usr/local"
ServerAdmin you@your.address
ServerName www.example.com:80
DocumentRoot "/usr/local/www/apache24/data"
Listen :80

Edit the /etc/hosts file and add the following line:

<ip-address>                  <hostname>.<domain>

eg:

192.168.1.1               hostname.example.org

Create a file named /boot/loader.conf or edit it if it is already present and add the following line:

accf_http_load="YES"

Add the following line to /etc/rc.conf

 apache24_enable="YES"

Test the apache server installation using the following command:

# /usr/local/sbin/apachectl start

MySQL – Installation and Configuration

# cd /usr/ports/databases/mysql56-server/
# make install
# make clean

Start MySQL

 # /usr/local/etc/rc.d/mysql-server onestart

Add the following line to the file /etc/rc.conf

 mysql_enable="YES"

Set password for my sql using the following command

# rehash
# mysqladmin -uroot password ''

Configuring mysql

Use the following command

 # cp /usr/local/share/mysql/my-default.cnf /etc/my.cnf

Restart mysql using the following commands

# /usr/local/etc/rc.d/mysql-server restart

PHP – Installation and Configuration

Use the following commands to install PHP5.5 and other supporting packages

# cd /usr/ports/lang/php55
# make install
# make clean

Check the option ‘Build Apache Module’ as shown in the image and continue

PHP_apache module

Edit /usr/local/etc/apache24/httpd.conf file and add the following lines under /AddType

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

And add the following line under LoadModule section

LoadModule php5_module        libexec/apache24/libphp5.so

Modify the line ‘DirectoryIndex index.html’ to the following

 DirectoryIndex index.php index.html

Now restart the apache server by using the following command

# /usr/local/sbin/apachectl restart