Home > Articles

MySQL

Installation

To prepare for installation, make sure you have plenty of room on your root partition. When you install MySQL server rpm, MySQL client rpm, MySQL shared rpm, and the MySQL development rpm, it requires over 26MB of space.

In addition to the space MySQL needs, the database files themselves require room. The default database storage directory is /var/lib/mysql. In that directory, you will find files and directories. The database files are stored in directories.

If you have a partition on which you want to store the database files, you will need to do some work after install. I will cover moving the entire MySQL database files to a new location after installation.

Installing the RPM

Copy all the MySQL rpm files into one directory. Run the rpm install command with all the MySQL rpms listed, putting a space between each one. You will get a printout similar to Listing 3.1.

Listing 3.1 Initial MySQL Installation

[root@winbook imp]# rpm -i MySQL-3.22.32-1.i386.rpm MySQL-client-3.22.32-1.i386.
rpm MySQL-shared-3.22.32-1.i386.rpm MySQL-devel-3.22.32-1.i386.rpm
Creating db table
Creating host table
Creating user table
Creating func table
Creating tables_priv table
Creating columns_priv table

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
/usr/bin/mysqladmin -u root password 'new-password'
See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at http://www.mysql.com
Support MySQL by buying support/licenses at http://www.tcx.se/license.htmy.

Starting mysqld daemon with databases from /var/lib/mysql
[root@winbook imp]#

Now select a password for the root user. The root user has full access to MySQL by default. The initial password for the root user is blank. Choose something you will not forget and that is difficult for other people to guess. For this book, I'll be using the password mypass. It is a terrible password and should not be used under any circumstance.

Run the command as shown. Note that MySQL does not prompt you to re-enter the password. You must get it right the first time!

[root@winbook /root]# mysqladmin -u root password 'mypass'

A Quick Test of the Install

Three things must be done to verify that MySQL installed correctly. First, run the rpm query (rpm —qa) command and make sure all the packages installed. Because I want to see all the packages installed, I have rpm dump the entire list and then grep for the packages I want. I use the search option -i, which is not case sensitive.

[root@winbook /root]# rpm -qa | grep -i mysql

Ouput

MySQL-3.22.32-1
MySQL-client-3.22.32-1
MySQL-shared-3.22.32-1
MySQL-devel-3.22.32-1

After this checks out, I look to see that the mysql daemons are running. I run the ps commmand with the ax command-line switch, and grep for mysql. You should get a printout similar to the following:

[root@winbook /root]# ps ax | grep -i mysql

Output

 529 ?    S   0:00 sh /usr/bin/safe_mysqld --user=mysql \pid-file=/var/
 563 ?    SN   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql
 621 ?    SN   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql
 622 ?    SN   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql

Finally, I run the mysql command-line program and take a look at the mysql database. The mysql database contains information about permissions and other databases in the system.

[root@winbook /root]# mysql mysql

Output

ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
[root@winbook /root]# mysql -pmypass mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 3.22.32

Type 'help' for help.

mysql>

The first time I attempted to use the mysql program, I got an error message because I did not enter the password. If you don't get an error message, it is because you did not set a password! The second time, I entered the password and it let me in. Note the password is entered immediately after the -p option with no spaces in between.

Now, show the table information. You must put a semicolon (;) at the end of every command. This signals to MySQL that you are finished entering the command, and to begin acting upon that command. If you press Enter before putting in a semicolon, simply enter the semicolon on the next line and then press Enter:

mysql> show tables;

Output

+-----------------+
| Tables in mysql |
+-----------------+
| columns_priv  |
| db       |
| func      |
| host      |
| tables_priv   |
| user      |
+-----------------+
6 rows in set (0.00 sec)

mysql>

Note

The mysql program allows commands to span multiple lines. You usually let the mysql program know that you are ready for it to interpret the command line(s) just entered by entering a semicolon as the last character in the line before pressing Enter. You can also use \G or \g as the signal to the mysql program to interpret the command line(s). These endings format the output a different way when using the mysql program.

The mysql utility also uses the readline library. This library enables the up arrow and down arrow keys to be used to recall previously entered command lines. These lines can be edited using the right and left arrow keys to move the cursor. After you press Enter, the new line is entered into the readline buffer and handed to the mysql program for interpretation.

When you use SQL statements in PHP, do not use the semicolon to signal the end of the statement. If you do, you will get an error. The semicolon is only used by the mysql utility to tell it to start processing your command.

You can show information from all the tables in the mysql database. The most interesting table in a new mysql database is the user table (see Listing 3.2). Let's look at the columns in the user table:

Listing 3.2 MySQL System User Table

mysql> show columns from user;
+-----------------+---------------+------+-----+---------+-------+
| Field      | Type     | Null | Key | Default | Extra |
+-----------------+---------------+------+-----+---------+-------+
| Host      | char(60)   |   | PRI |     |    |
| User      | char(16)   |   | PRI |     |    |
| Password    | char(16)   |   |   |     |    |
| Select_priv   | enum('N','Y') |   |   | N    |    |
| Insert_priv   | enum('N','Y') |   |   | N    |    |
| Update_priv   | enum('N','Y') |   |   | N    |    |
| Delete_priv   | enum('N','Y') |   |   | N    |    |
| Create_priv   | enum('N','Y') |   |   | N    |    |
| Drop_priv    | enum('N','Y') |   |   | N    |    |
| Reload_priv   | enum('N','Y') |   |   | N    |    |
| Shutdown_priv  | enum('N','Y') |   |   | N    |    |
| Process_priv  | enum('N','Y') |   |   | N    |    |
| File_priv    | enum('N','Y') |   |   | N    |    |
| Grant_priv   | enum('N','Y') |   |   | N    |    |
| References_priv | enum('N','Y') |   |   | N    |    |
| Index_priv   | enum('N','Y') |   |   | N    |    |
| Alter_priv   | enum('N','Y') |   |   | N    |    |
+-----------------+---------------+------+-----+---------+-------+
17 rows in set (0.00 sec)

mysql>

The user table has many columns. The column names are fairly obvious. This table controls most of the ability to access this database system. For now, let's look at the first four columns for all the rows in the database:

mysql> select host,user,password,select_priv from user;
Output
+-----------+------+------------------+-------------+
| host   | user | password     | select_priv |
+-----------+------+------------------+-------------+
| localhost | root | 6f8c114b58f2ce9e | Y      |
| winbook  | root |         | Y      |
| localhost |   |         | N      |
| winbook  |   |         | N      |
+-----------+------+------------------+-------------+
4 rows in set (0.00 sec)

mysql>

Briefly, the root user can access the database from the localhost (on loopback address 127.0.0.1) using a password. If the root user accesses the database from the winbook host, no password is needed.

Note

Even though winbook and localhost are the same machine in this case, any command-line invocations of programs use the loopback adapter by default. This means that you will always require a password to access MySQL. However, if someone is able to spoof and pretend they are coming from the winbook host, MySQL does not require a password.

To fix this problem, you need to run mysql as root and enter an update command where you update the password for all occurrences of the root user:

mysql> select Host,User,Password from user;

Output

+-----------+--------+------------------+
| Host   | User  | Password     |
+-----------+--------+------------------+
| localhost | root  | 6f8c114b58f2ce9e |
| winbook  | root  |         |
| localhost |    |         |
| winbook  |    |         |
| localhost | impmgr | 5567401602cd5ddd |
+-----------+--------+------------------+
5 rows in set (0.00 sec)
mysql> UPDATE user SET Password=PASSWORD('mypass') where User='root';
Query OK, 1 row affected (0.12 sec)
Rows matched: 2 Changed: 1 Warnings: 0
mysql> select Host,User,Password from user where User='root';
+-----------+------+------------------+
| Host   | User | Password     |
+-----------+------+------------------+
| localhost | root | 6f8c114b58f2ce9e |
| winbook  | root | 6f8c114b58f2ce9e |
+-----------+------+------------------+ 2 rows in set (0.01 sec)

The root user also has select privilege to databases. Any other user has no select privilege, whether coming from the localhost or from the winbook host. If you examine the rest of the columns in the user table, you will see that root has full privileges, and other users have no privileges. This is the default security setup for MySQL.

To exit the mysql command-line utility, enter quit and press Enter. For some reason, no semicolon is needed at the end of this command.

Troubleshooting the Install

I have never had the MySQL install fail unless I was installing it on an early version of an operating system. If you attempt to install this on a stock Red Hat 5.x system then MySQL might very well not work. If you must do this, be sure to upgrade your glibc package. If this library is too far out of date, MySQL will not function.

The other possibility for an install failure is lack of disk space. You must have plenty of room in the partition that holds the /usr and /var directories. If you don't then MySQL might install, but fail to work properly. I strongly recommend that you have 100MB of free disk space in the partition that holds the /var/lib/mysql directory after you have installed MySQL. If you don't you might have a surprise failure after a short time, unless you monitor your disk usage carefully.

 

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