Posts tagged ‘FreeBSD’

How to change the system date from the shell on FreeBSD?

The system date and time can be changed with the date command.

Set Date only

date YYMMDD

or

date YYYYMMDD

Set Date and Time

date YYMMDDHHMM

or

date YYYYMMDDHHMM

Set Time only

date HHMM

Example
So for example, if you want to set the date to Nov. 6, 2009 and the time to 8:58, you would use this command:

# date 0911060858

See man date for more information.

How to start, stop, restart MySQL on FreeBSD or Red Hat?

FreeBSD

Starting MySQL


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

Stopping MySQL


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

Restarting MySQL


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

Red Hat

Starting MySQL


/etc/init.d/mysql start

or


/sbin/service mysql start

Stopping MySQL


/etc/init.d/mysql stop

or


/sbin/service mysql stop

Restarting MySQL


/etc/init.d/mysql restart

or


/sbin/service mysql restart

How to install MySQL on FreeBSD 7.2 or on Red Hat 5.4?

FreeBSD
There are two easy ways on FreeBSD:

From Ports

You can install easily from Ports. Make sure your ports tree is up to date:

$ su

Password:

ServerName#

ServerName#

ServerName#

portsnap fetch

portsnap extract

portsnap udpate

Then just do this to install MySQL on FreeBSD.

ServerName#

ServerName#

cd /usr/ports/databases/mysql51-server

make install

Or if you want to use utf8 by default, run this command:

ServerName# make WITH_CHARSET=utf8 install

MySQL 5.1 Server (and MySQL 5.1 client) will download, compile, and install automagically for you.

From Packages

You can also install easily as a binary package with this simple command.

ServerName# pkg_add -r mysql51-server

Make sure to secure you MySQL installation.
http://dev.mysql.com/doc/mysql-security-excerpt/5.1/en/default-privileges.html

Red Hat
Using RPM

You have to go to the MySQL site and download the MySQL 5.1 server RPM and install it.
http://dev.mysql.com/downloads/

It does not automatically install the MySQL client, you have to download that as a separate RPM and install it.

Using yum

Since I didn’t have a MySQL license, yum didn’t work, so I don’t know if it can be installed using yum.

Make sure to secure you MySQL installation.
http://dev.mysql.com/doc/mysql-security-excerpt/5.1/en/default-privileges.html


Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

How to create a UTF-8 Unicode Database on MySQL and make UTF-8 Unicode the default?

How to create a UTF-8 Unicode Database on MySQL?

I am not going to cover installing, I have done that here:
How to install MySQL on FreeBSD 7.2 or on Red Hat 5.4?

So when you open MySQL using the command line MySQL client, you can see what Character Set your server is configured to use with this command:

show variables like 'character_set_server';

Often the default is Latin-1. I wish UTF-8 was the default but it is not.

You can see the language your database is created with by using this command:

show create database dbname

Again, usually the default is Latin-1 and again, I wish the default were UTF-8 but it is not.

So how do I make my MySQL database UTF-8?
How do I make UTF-8 the default?

I am going to find out…

Ok, so I have MySQL installed on two different platforms:
FreeBSD 7.2 x64.
Red Hat 5.4 x64.

My question are these:
What level do you set the Unicode setting at? Install instance, database, or column type.

MySQL – Looks like it can be configured globally in the my.cnf or it can be database specific.

To configure globally

Add the following to the my.cnf file:

[mysqld]
init_connect=’SET collation_connection = utf8_general_ci’
init_connect=’SET NAMES utf8′
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake

Note: There are other options for collation besides utf8_general_ci such as utf8_unicode_ci. See this article:
http://dev.mysql.com/doc/refman/5.1/en/charset-unicode-sets.html

Do I have to create the database in a special way?

Not if you configure the setting globally. However, if you don’t configure unicode support globally then yes you have to create your database in a specific way.

I found this post that is for an applications that uses a MySQL Unicode database. I don’t care about the application, just the MySQL data.
http://dev.mysql.com/doc/refman/5.1/en/create-database.html
http://dev.mysql.com/doc/refman/5.1/en/charset-applications.html

So the syntax will be:

CREATE DATABASE mydb   DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

Do I have to compile differently to get unicode support?

I didn’t have to recompile on either FreeBSD or Red Hat.

Is there differences for each platform?

Slight differences.

FreeBSD

FreeBSD has the MySQL client as a dependency so it gets installed with the server with out any extra work.

The Database folder is /var/db/mysql.

For the global configuration there is not a my.cnf file created by default.

FreeBSD has example my.cnf files located here:

/usr/local/share/mysql
/usr/local/share/mysql/my-huge.cnf
/usr/local/share/mysql/my-innodb-heavy-4G.cnf
/usr/local/share/mysql/my-large.cnf
/usr/local/share/mysql/my-medium.cnf
/usr/local/share/mysql/my-small.cnf

You can create your own my.cnf or you can copy one of the examples.

In order to get the my.cnf to work, you should copy it and change the owner and add the [mysqld] settings.

#
#
#
?
?
?
?
?
?
?
?
#
cp /usr/local/share/mysql/my-medium.cnf /var/db/mysql/my.cnf
chown mysql:mysql /var/db/mysql/my.cnf
cat << EOF >> /var/db/mysql/my.cnf
[mysqld]
init_connect=’SET collation_connection = utf8_general_ci’
init_connect=’SET NAMES utf8′
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
EOF

Red Hat

Red Hat does not have the MySQL client installed with the server, you have to download a separate RPM and install it. But it is really easy. Download both RPMs and install them.

The Database folder is /var/lib/mysql.

For the global configuration there is not a my.cnf file created by default.

Red Hat has example my.cnf files located here:

/usr/share/mysql
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-small.cnf

Same as FreeBSD, there isn’t one used by default and you have to copy one and use it.
You can create your own my.cnf or you can copy one of the examples.

In order to get the my.cnf to work, you should copy it and change the owner and add the [mysqld] settings.

#
#
#
?
?
?
?
?
?
?
?
#
cp /usr/share/mysql/my-medium.cnf /var/lib/mysql/my.cnf
chown mysql:mysql /var/lib/mysql/my.cnf
cat << EOF >> /var/lib/mysql/my.cnf
[mysqld]
init_connect=’SET collation_connection = utf8_general_ci’
init_connect=’SET NAMES utf8′
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
EOF

Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

How do I install FreeBSD?

I have an article depending on the version you are trying to install

I also have aarticles for dual-booting.

What are the first commands I run after installing FreeBSD? Or How to patch FreeBSD? Or How to install ports on FreeBSD?

Ok, so you just installed FreeBSD, an maybe you are not familiar with it, so you think, “What now?”.

Well, think about what you do when you install any platform. You do three things:

  1. Apply patches/updates.
  2. Install software
  3. Post-installation configuration of system and software

For example, when you install a new windows operating system, it is common to go to Windows Update and update your server. Then you install software such as microsoft office, etc… The same for servers. You update the server, then maybe you add your server software. Then you configure it some more.

The order may vary for every install or you may even do this three step process multiple times.

Just because you are on FreeBSD does not mean the same three step process doesn’t apply. This three item process is operating system independent. It is the first thing I do on FreeBSD as well.

So here are the first commands that I run after logging into a new FreeBSD install.

$ su

Password:

ServerName#
ServerName#
ServerName#
ServerName#
freebsd-update fetch
freebsd-update install
portsnap fetch
portsnap extract

Same commands in a nice script/code box you can use to copy and paste.

freebsd-update fetch
freebsd-update install
portsnap fetch
portsnap extract

Let me explain what each command does:

  1. freebsd-update fetch – This download patches that have been released for the version of FreeBSD you have installed. It does not install the patches.
  2. freebsd-update install – This command installs the patches that were previously download.
  3. portsnap fetch – This download a compressed version of the ports tree. Ports means applications that have been ported or developed to compile and run on FreeBSD. So the ports tree is basically a database of available software that can be install on FreeBSD.
  4. portsnap extract – This extracts the compressed version of the ports tree.

So with these four commands you have your system updated/patched. You also have all the software that is available ready to be installed.

Update 1:

I am not sure why i didn’t know this before, but you can combine each pair of commands into one command:

ServerName#
ServerName#
freebsd-update fetch install
portsnap fetch extract
freebsd-update fetch install
portsnap fetch extract

Stay tuned for my article on searching the ports tree.

Update 2:

As you can read in the comments, it is good to know that you only have to “extract” the ports tree once and for every subsequent update to the ports tree, you should only run it with the “update” command as shown.

portsnap fetch update