Installing and configuring Mysql server on Freebsd

Reading Time: 2 minutes

Go to the /usr folder

cd /usr

and then extract updates

portsnap fetch extract

then go to mysql client folder in ports(the version may change on your ports version and updates)

/usr/ports/databases/mysql56-client

then issue the command to install client

make install clean

and then navigate to the server folder

cd /usr/ports/databases/mysql56-server

then install it

make install clean

and then add the mysql instance to be started in boot

echo 'mysql_enable="YES"' >> /etc/rc.conf

and then start the mysqlserver

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

and then to check whether the service is running issue the below command and if you see below output mysql is up and runnig

root@virtualbsd:/usr/ports/databases/mysql56-server # ps -waux | grep mysql
mysql 27125  0.0  0.0  17064      0  -  IWs  -        0:00.00 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/var/db/mysq
mysql 27235  0.0 62.3 649464 148088  -  S     1:52AM  0:00.90 /usr/local/libexec/mysqld --defaults-extra-file=/var/db/mysql/my.cnf 
root  27243  0.0  0.5  10512   1156  0  RL+   1:52AM  0:00.00 grep mysql

later on issue the following commands

chown -R mysql /var/db/mysql/
chgrp -R mysql /var/db/mysql/
/usr/local/bin/mysqld_safe –user=mysql &

then we are good to set a new password for the root

/usr/local/bin/mysqladmin -u root password ENTERYOURNEWPASSHERE

and then issue the command for automated post installation settings

mysql_secure_installation

then restart your mysql server

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

if you want to access your mysql server from remote carry out following commands

connect to your mysql server

mysql -p

and then grant access to root

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
IDENTIFIED BY 'YOURPASSWORDHERE' WITH GRANT OPTION;

then issue grant command one more time

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "YOURPASSWORDHERE";

then flush privileges

flush privileges;

then quit

quit

then restart your mysql server

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

then launch mysql workbench and connect to your server

voilà!

freebsdmysqlworkbench