MySQL Installation
From T5C
In this article, we will cover the MySQL installation process on CentOS using yum. We will also cover post-install configuration steps to leave your database server ready for production.
Contents |
[edit] About yum
The Yellow Dog Update Manager or yum is the preferred method of updating and installing new software on the CentOS Linux distribution. It's based on the Red Hat Package Manager (RPM) and uses a distributed system of repositories and mirrors to manage package distribution. The main advantage of yum over plain RPM is its capacity to handle dependencies and version conflicts.
To see a list of all available yum list packages in the yum system as configured on your server, enter the following:
yum list
To install a pcakage, type:
yum -y install package-name
The package name can be obtained from the listing produced by the first command.
[edit] Installing MySQL with yum
To install the MySQL database server via yum, you simply issue the following command:
yum -y install mysql-server
This will download and install MySQL and all required dependencies. That's it! After yum has finished you can proceed to configure the service for standalone operation as we'll see next.
[edit] Disabling MySQL Networking
Since our LAMP server is hosted on a single machine, our MySQL database will never need to be accessed remotely across the network. In light of this, we will configure the MySQL daemon to run without any networking code enabled. This will ensure our database server is un-hackable over the net and will run more efficiently because of the lower executing processes.
We have to edit the MySQL initialization script with this command:
vi /etc/init.d/mysqld
To edit in vi, use these controls:
- Move around with the keyboard arrow keys (up, down, left, right).
- Press i to start inserting text at the current cursor position.
- Press Escape on the keyboard to leave insertion mode.
- Pres x on the keyboard to delete the character at the current cursor position.
- Press : on the keyboard to enter command mode.
- Press Escape on the keyboard to exit command mode.
- Enter wq in command mode to save and exit.
There's much more to the vi text editor, but this will get you started with basic insertion and deletion functions.
Now find this line (may be slightly different on your install):
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --pid-file="$mypidfile" >/dev/null 2>&1 &
And change it to this by inserting the --skip-networking parameter:
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --pid-file="$mypidfile" --skip-networking >/dev/null 2>&1 &
Now save and quit with :wq and we are ready to start the MySQL daemon.
[edit] Starting MySQL
To start MySQL, enter the following:
service mysqld start
When you see the [ OK ] message, then MySQL is up and running.
[edit] Setting the MySQL root Password
The very first step after MySQL is running is to set its root password. As in Linux, the root account in MySQL has full control over the database server. It isn't the same account as the Linux root account though, and thus can have a different password.
To set the MySQL root account password type:
mysqladmin -u root password 'VeRyhARdPassWoRD'
where you specify the password as the string between the single quotes.
[edit] Logging In to MySQL
Finally, you can now log in to your brand new MySQL server:
mysql -u root -p
MySQL will prompt for the root password and once you enter that, you'll be greeted with a message somewhat like this:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 4.1.20 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
Now your MySQL server is ready to go. But we still have one final step to complete so logout with:
\q
[edit] Starting MySQL Automatically at Boot
Now that we know MySQL is working fine, we have to make it startup automatically at each system reboot or startup:
chkconfig mysqld on
This will make the MySQL daemon start automatically whether its a planned system restart or an unexpected failure or crash.

