Installing MySQL

Synopsis:

MySQL Community Server is a freely downloadable version of the world's most popular open source database that is supported by an active community of open source developers and enthusiasts. The Enterprise version is now distributed and supported by Oracle.

I. Installation
Log into the Freebsd system as root. (Assumes networking is already configured.) MySQL is included in the FreeBSD Ports. If you need to install Ports, go Here

Package Method:

#
# pkg install -y mysql81-server
#

Ports Method:

#
# cd /usr/ports/databases/mysql81-server && make install clean
#
Options for Ports Method:
  Permissable Storage Engine - leave as is
  Use the default option settings, press [Enter] to continue ...

Mirrored sites will now be searched for the tarred program file (apprx. 317MB) and downloaded. Then any dependencies are checked and those source files are downloaded and installed. At last the actual MySQL installation will proceed, first the server, then the client. The installation process takes about 30 minutes to compile the program on the Celeron 1.6G system.

II. Post Install Configuration
1. Add the startup script to rc.conf.
#
# sysrc mysql_enable="YES"
#
2. Start the MySQL Service.
#
# service mysql-server start
#
3. By defaut, Mysql81 has no root password. To set the root password:
Enter the new password in single quotes.
#
# /usr/local/bin/mysqladmin -u root -p password 'new-password'
#

Password for MySQL server must be in single quotes.

4. Miscellaneous

Start MySQL command tool:
$
$ mysql -u root -p
$ Enter password:
$
Create a database:

mysql> CREATE DATABASE dbname;

Create a user for the database (putting quotes around the password is required):

mysql> GRANT ALL ON dbname.* TO db_user@localhost IDENTIFIED BY 'password';

Prepare to restore a database:

mysql> USE dbname;

Restore the structure:

mysql> SOURCE dbname_structure.sql;

Restore the data:

mysql> SOURCE dbname_data.sql;

Check tables of a database:

mysql> USE dbname;
mysql> SHOW TABLES;

Restore database from single dump file:
$
$ mysql -u root -p dbname < dump-file.sql
$ Enter password:
$
Backup a database to a dump file:
$
$ mysqldump -u root -p dbname > dump-file.sql
$ Enter password:
$