Create test databases in MySQL
Sometimes you need to create a test database on a development MySQL server, to run some tests on, and you want to populate it with many records, to make your tests more meaningful. This document lists a couple of quick and dirty ways that I use to achieve that.
Using /usr/share/dict/words
On most Linux distributions, there is a file at /usr/share/dict/words
which contains a list of words, each on a
separate line. On my Linux Mint 15 installation, I count more than 99000 lines. The following commands will put those
words in a table called words
, in a database called test
, one word per table row.
Create the table:
mysql> CREATE TABLE words (id INT AUTO_INCREMENT, word VARCHAR(256));
Populate the table with the words. I 'm using double quotes to wrap the words, since many of them already contain a single quote:
while read word; do mysql test -e "INSERT INTO words (word) VALUES (\"$word\")"; done < /usr/share/dict/words
Using /var/log/messages
I have also used the contents of /var/log/messages
to populate a table, and that is documented in the blog post
How to create a large MySQL database for tests. That is a painfully
slow method, but can create tables that are many GigaBytes in size, which might be necessary for some tests.
Zentyal
See Also
This is a series of articles for setting up a network with Zentyal acting as the Primary Domain Controller, published at tecmint.com:
- Install Zentyal as PDC (Primary Domain Controller) and Integrate Windows System
- How to Manage Zentyal PDC (Primary Domain Controller) from Windows System
- Creating Organizational Units (OU) and Enabling GPO (Group Policy) in Zentyal PDC Server
- Setup File Sharing and Permissions for All Users in Zentyal 3.4 PDC
- Integrate Ubuntu System in Zentyal PDC (Primary Domain Controller)
- Integrate CentOS/RedHat/Fedora in Zentyal PDC (Primary Domain Controller)
- Integrate Ubuntu 14.04 (Trusty Tahr) to Zentyal PDC (Primary Domain Controller)
- Installing FTP Server and Mapping FTP Directories in Zentyal PDC
- Install and Configure Web Services (Apache Virtual Hosting) on Zentyal Server
- Enabling UserDir and Password Protect Web Directories on Zentyal Webserver
- Installing Pydio File Sharing Platform on Zentyal 3.4 Webserver
- How to Install and Configure OpenVPN Server on Zentyal 3.4 PDC
- Install and Configure Zentyal Linux 3.5 as A BDC (Backup Domain Controller)
- Joining CentOS 7 Desktop to Zentyal PDC (Primary Domain Controller)
Articles for Zentyal 3.5, released on July 1st 2014:
virsh
List all VMs:
virsh list --all
Automatically boot a VM when the host boots:
virsh autostart vm.zindilis.net
Disable automatic start:
virsh autostart --disable vm.zindilis.net
Manually power on a VM:
virsh start vm.zindilis.net
Gracefully shutdown a VM:
virsh shutdown vm.zindilis.net
Forcefully shutdown a VM:
virsh destroy vm.zindilis.net
/etc/shadow
The fields, delimited by :
are:
- Username
- Password (hashed)
- Last password change (in days since 1970-01-01)
Fields
Notes on specific fields.
Username
Fairly straightforward. The lenght used to be restricted to 8 characters maximum in very old distributions, now it's 32 characters on most distributions.
Password
An empty field, will allow the user to login without providing a
password, whereas a field that starts with, or only contains an asterisk
*
indicates a disabled account.
The first characters of this field define the hashing algorithm, one of:
- MD5 - password starts with
$1$
- Blowfish - password starts with
$2a$
- SHA-256 - password starts with
$5$
- SHA-512 - password starts with
$6$
dirname
The dirname
command will give you the path of the file that you provide as
parameter, up to its parent directory. If the parameter is an absolute path,
the absolute containing directory will be returned, otherwise it will be the
relative path.
For example, for the file /home/marios/.bash_aliases
:
{% highlight bash %} mariosz@super-mario:~$ dirname /home/marios/.bashaliases /home/marios mariosz@super-mario:~$ dirname ~/.bashaliases /home/marios mariosz@super-mario:~$ dirname .bash_aliases . {% endhighlight %}
See also
Set up an HTTP Repository from RHEL DVD
RHEL can be installed from various different sources. One of them is over the network, from an HTTP accessible repository. Here's how to create such a repository:
You will first need to install
httpd
from the RHEL DVD. See Install packages from RHEL DVD with yum on how to do that.After you have installed
httpd
, enable it and start it:chkconfig httpd on service httpd start
At this point, you should be able to open
http://localhost/
from the same system on which you are working.Create a directory for the repository:
mkdir /var/www/html/rhel
Copy all the files from the DVD to the repository. Assuming that either the DVD or the
.iso
image is mounted at/media/rhel
:cp --recursive --archive /media/rhel/. /var/www/html/rhel/
Change the SELinux context of the files in the repository:
chcon --recursive --reference=/var/www/html/ /var/www/html/rhel/
At this point the repository is only accessible from the system on which it runs, since
iptables
by default does not allow HTTP traffic from other hosts. To open this access, edit your/etc/sysconfig/iptables
and add this line before theCOMMIT
command:-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
...and reload the firewall:
service iptables reload
Alternatively, you can do from the command line:
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT service iptables save
Install packages from RHEL DVD with yum
There are a lot of packages available on the RedHat Enterprise Linux
Installation DVD (I count 3764 .rpm
files on version 6.5 Beta), and you can
mount the DVD on your system and then use it as a repository to install them
with yum
. To do that:
First you need access to the files on the DVD. If the disk is inserted in a physical DVD drive on your system, or if you are working in a virtual machine and you have the DVD attached to the VM's virtual optical drive, you can mount it with:
mkdir /media/rhel mount /dev/cdrom /media/rhel
Otherwise, if you have the
.iso
image locally on the system, you can mount that one instead:mkdir /media/rhel mount -o loop /root/rhel.iso /media/rhel
Next, you need to create a Yum repository pointing to the mounted disk. To do that, create a new
.repo
file in the/etc/yum.repos.d/
directory:vi /etc/yum.repos.d/rhel-media.repo
...and populate it with the following lines:
[rhel-media] name=rhel-media baseurl=file:///media/rhel gpgcheck=1 enabled=1 gpgfile=file:///media/rhel/RPM-GPG-KEY-redhat-release
If you don't remember the configuration lines listed above, you can peak at other
.repo
files in/etc/yum.repos.d/
.
You can then install packages, for example httpd
with simply doing:
yum install httpd
You can also verify that the DVD is the source for that package with:
yum info httpd | grep Repo
Repo : rhel-media
Bash Scripting
Functions
- Deeper into Function Complexities with Shell Scripting at tecmint.com, explains local versus global variables and recursion.