Home > Articles

MySQL

Configuration for Use with IMP

You can configure MySQL by hand, or you can use the script that the IMP software package includes. I will show you how to configure MySQL for IMP by hand, and then I will show you how to do it using the script. To get to the MySQL script, you must unpack the IMP tarball.

As you go through this exercise, if you make a mistake, you can use the SQL DROP command to drop the table or database you created. You can then start over. Please don't DROP any table in the mysql database. Don't DROP the mysql database! If you do, you will have to reinstall MySQL!

First, let's look at the disk storage issue. I have decided I want to store the MySQL database files in the /home partition because I have plenty of free space on that partition. Because I won't have many users who can log in through telnet or secure shell on this machine, it is safe to do this.

Before you move things around, you need to stop MySQL. When you installed the rpm, an init script was stored in the /etc/rc.d/init.d directory. It is called mysql. It is a convention for all init scripts to obey the commands start and stop. Most also obey the restart command. So, to stop the MySQL server, run the following:

[root@winbook imp-2.0.11]# /etc/rc.d/init.d/mysql stop
Killing mysqld with pid 622

The script will always respond with the process ID of the mysqld server. It also places a message in an error log file in the data directory. The logfile name is made up of the local machine's hostname, obtained by running the hostname command, with .err tacked on the end. If you run cat on the .err file in the /var/lib/mysql directory, you will see the startup and shutdown of the MySQL server:

[root@winbook mysql]# ls /var/lib/mysql

Output

mysql test winbook.err
[root@winbook mysql]# cat /var/lib/mysql/winbook.err
mysqld started on Sat Mar 18 08:31:42 CST 2000
/usr/sbin/mysqld: ready for connections
000318 8:31:57 /usr/sbin/mysqld: Normal shutdown

000318 8:31:57 /usr/sbin/mysqld: Shutdown Complete

mysqld ended on Sat Mar 18 08:31:57 CST 2000

Now that MySQL is stopped, you will move the database directory to where you want it. Linux will not allow you to move directories across file systems. Therefore, you must copy the directory. If you use the -a command-line option for cp, it will preserve permissions and directory structure. Follow these commands, and notice the results in Listing 3.3.

Listing 3.3 Moving MySQL's Database To Another Location

[root@winbook lib]# cd /var/lib
[root@winbook lib]# cp -a mysql /home/mysql
[root@winbook lib]# ls /home
Office51 httpd lost+found maxfield mysql root
[root@winbook lib]# ls /home/mysql
mysql test winbook.err
[root@winbook lib]# ls -l /home
total 36
drwxr-xr-x 26 root   root     4096 Feb 18 16:26 Office51
drwxr-xr-x  5 root   root     4096 Feb 28 18:11 httpd
drwxr-xr-x  2 root   root    16384 Feb 18 12:38 lost+found
drwx------ 12 maxfield maxfield   4096 Mar 7 19:23 maxfield
drwxr-xr-x  4 mysql  root     4096 Mar 18 08:31 mysql
drwxrwx--- 26 root   root     4096 Mar 19 2000 root
[root@winbook lib]# pwd
/var/lib
[root@winbook lib]# mv mysql mysql.old
[root@winbook lib]# ln -s /home/mysql mysql
ls[root@winbook lib]# ls
cddb dosemu games mysql mysql.old nfs rpm slocate svgalib texmf xkb
[root@winbook lib]# ls -l mysql
lrwxrwxrwx  1 root   root      11 Mar 18 10:14 mysql -> /home/mysql
[root@winbook lib]# cd mysql
[root@winbook mysql]# ls -l
total 12
drwx--x--x  2 mysql  root     4096 Mar 18 11:14 mysql
drwxr-xr-x  2 mysql  root     4096 Mar 18 11:14 test
-rw-r--r--  1 root   root     960 Mar 18 08:31 winbook.err
[root@winbook mysql]# pwd
/var/lib/mysql
[root@winbook mysql]# df .
Filesystem      1k-blocks   Used Available Use% Mounted on
/dev/hda7       7178940  1101984  5712284 16% /home
[root@winbook mysql]#

What happened? First, I copied the mysql data directory, which is under /var/lib/ to the /home directory, using the -a option. Then I made sure it was there, with the proper permissions. After that was verified, I made sure I was still in the /var/lib directory, and moved the mysql directory to mysql.old. If I make a mistake, I still have the original directory. I then created a soft link to the new mysql data directory, and did a cd to that directory. I verified that directory was indeed on the /home partition by using the df command.

If you have plenty of room on your root partition, you don't have to do this. If you have a partition mounted under a directory other than /home that you would like to put the data directory on, you can use it instead.

Finally, if you want to create an /etc/my.cnf file or modify the safe_mysql startup script to place the data directory elsewhere, you can. However, this can require modifying MySQL every time you upgrade it, and at the least requires additional study. It is a matter of personal taste. I believe in the motto "If it ain't broke, don't fix it." I recommend you become familiar with MySQL's default behavior before you take any such action.

To start MySQL after you have moved the database, enter the following:

[root@winbook /root]# /etc/rc.d/init.d/mysql start
[root@winbook /root]# Starting mysqld daemon with databases from /var/lib/mysql

[root@winbook /root]# ps ax | grep my

Output

 1145 pts/1  S   0:00 sh /usr/bin/safe_mysqld --user=mysql \pid-file=/var/
 1162 pts/1  SN   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql
 1164 pts/1  SN   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql
 1165 pts/1  SN   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql
[root@winbook /root]#

You will have to press Enter after the "Starting ..." message is displayed. Running the ps command gives you total assurance that MySQL has started. You can check the error file in the /var/lib/mysql directory for a final cross check.

Now that MySQL is started, run the mysql command-line utility and start creating the IMP database.

[root@winbook /root]# mysql -pmypass mysql

Output

mysql> INSERT INTO user ( host, user, password )
  ->  VALUES (
  ->    'localhost',
  ->    'impmgr',
  ->    password( 'impmgr' )
  ->    );
Query OK, 1 row affected (0.45 sec)

This SQL statement created a row in the user database that allows the impmgr user access. The password for impmgr is impmgr.

mysql> INSERT INTO db (
  ->    host, db, user,
  ->     Select_priv, Insert_priv, Update_priv, Delete_priv,
  ->     Create_priv, Drop_priv )
  ->    VALUES (
  ->    'localhost',
  ->    'imp',
  ->    'impmgr',
  ->    'Y', 'Y', 'Y', 'Y',
  ->    'Y', 'Y'
  ->     );
Query OK, 1 row affected (0.00 sec)

The INSERT INTO db statement sets the privileges for the impmgr user. That user is allowed to run the following SQL commands on the imp database: SELECT, INSERT, UPDATE, DELETE, CREATE, and DROP.

mysql> CREATE DATABASE imp;
Query OK, 1 row affected (0.00 sec)

This statement actually creates the database. If you bring up an xterm and do an ls of the /var/lib/mysql directory, you will see a new directory named imp. This directory contains all of imp's database files.

mysql> use imp;
Database changed

The use imp command tells the mysql utility to apply all the following SQL statements to the imp database, unless specifically overridden.

mysql> CREATE TABLE imp_addr (
  ->  user text,
  ->  address text,
  ->  nickname text,
  ->  fullname text
  -> );
Query OK, 0 rows affected (0.46 sec)

mysql> CREATE TABLE imp_pref (
  ->  user text,
  ->  fullname text,
  ->  replyto text,
  ->  lang varchar(30),
  ->  sig text
  -> );
Query OK, 0 rows affected (0.00 sec)

The CREATE commands created the imp tables. If you run the 'show tables;' command under mysql, it will list the two tables just created. The command 'show columns from imp_addr;' will show the columns for that table. Give it a try.

mysql> quit
Bye
[root@winbook /root]# mysqladmin -pmypass reload

The mysqladmin program is used to reload the grant tables so that you can use the new database privileges without taking the server down.

The easy way to accomplish this is to run the mysql_create.sql script, which is placed in the imp directory. The easiest way to run this script is to cd into the imp-2.0.11/config/scripts/ directory and run the following command:

[root@winbook /root]#mysql -pmypass <mysql_create.sql

This will interpret the statements in that text file as if they had been typed from the command line. This is a very powerful feature of MySQL. It enables you to build useful queries and keep them for future use.

Tip

Web-Based MySQL Administration

At http://phpwizard.net/projects/phpMyAdmin/index.html you will find a PHP Web application that can help you manage MySQL. It enables you to manage a MySQL database using a browser and makes administrative work much simpler.

After you have installed PHP and MySQL, you are ready to install phpMyAdmin. The work done while preparing for IMP has also prepared the system for phpMyAdmin. You do have to edit one of the .php3 files in phpMyAdmin to enter the MySQL database name and password.

With phpMyAdmin, you can create and drop databases and tables. You can also add and remove fields and perform other administrative chores.

I have found phpMyAdmin to be very useful when trying to create or delete tables. After you have filled out a form that describes the table, it generates the SQL for you. You can use this information to create script files for later use.

For now, phpMyAdmin has some bugs. I have had it crash on me several times. However, its usefulness is good enough for me to ignore the occasional crash.

From a security point of view, phpMyAdmin is terrible. After it is installed, everyone who uses that Web page has unrestricted access to the MySQL database. I strongly recommend that you do not put your server on the Internet with phpMyAdmin active. If you do, you must configure your Web server to serve only the phpMyAdmin Web pages to your local network. You should also protect the Web pages with a password. Be careful!

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020