Web www.freebsdmadeeasy.com
Main Menu

Installing and setting up a MySQL server

Installing the MySQL port

The MySQL database server can be installed with the following commands

# cd /usr/ports/databases/mysql41-server
# make install

A start up script is installed to /usr/local/etc/rc.d and the databases are stored in /var/db/mysql

Starting MySQL

/etc/rc.conf must contain the following line to allow the MySQL server to start

mysql_enable="YES"

Once this line is there you can run the start up script with

# sh /usr/local/etc/rc.d/mysql-server.sh start

Setting the root password

After MySQL has start you need to set passwords on both root accounts and the two anonymous accounts. By default these are left blank and give full access to the database server to anyone.

To set a password on the anonymous accounts use

# mysql -u root
# SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
# SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');

To set a password for the root account use

# mysql -u root
# SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
# SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

For more information on setting up these initial accounts check out the MySQL manual.

Managing your MySQL server with phpMyAdmin

phpMyAdmin is an amazing tool for managing your new MySQL database. It has a web interface and allows you to perform SQL queries, create new databases, add users, change priveldges, and back up the database. Go here to learn about installing phpMyAdmin. It requires both the Apache Web Server and PHP.