Install Mysql 4 server on Centos 5
Links for common Mysql topics, such as Installation, Setup/Configuration, or basic usage.
Contents
Introduction
Installation
Stopping and Starting MYSQL
Changing Mysql Root Password
Command Line Backup and Restoration
Introduction
MYSQL is a database server, which stores data in a table which in turn make up a database. Data is accessed, updated and inserted using SQL statements which allow vast amount of different queries to be performed on the data for a wide variety of reasons.
MYSQL is widely used in web applications and is required for applications such as:
Blogs:
- Wordpress
Galleries:
- Gallery
- Camera Life
Forums:
- phpBB
- Invision Power Board
- PHP Forum Script
Content Management Systems:
- PHPNuke
- Drupal
- PHP-Fusion
MYSQL is used all over the internet, Websites such as Facebook, Wikipedia, Google (except for searches), Drupal, Flickr.
Installation
Installing MYSQL is very easy. In SSH Type the following.
[root@vps ~]# yum install mysql mysql-server
Yum will look for the files required to install MYSQL.
Setting up Install Process Setting up repositories update 100% |=========================| 951 B 00:00 base 100% |=========================| 1.1 kB 00:00 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Reading repository metadata in from local files primary.xml.gz 100% |=========================| 172 kB 00:00 update : ################################################## 538/538 primary.xml.gz 100% |=========================| 611 kB 00:00 base : ################################################## 1599/1599 primary.xml.gz 100% |=========================| 190 B 00:00 primary.xml.gz 100% |=========================| 36 kB 00:00 extras : ################################################## 141/141 Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for mysql to pack into transaction set. mysql-4.1.22-2.el4.i386.r 100% |=========================| 36 kB 00:00 ---> Package mysql.i386 0:4.1.22-2.el4 set to be updated ---> Downloading header for perl-DBI to pack into transaction set. perl-DBI-1.40-9.i386.rpm 100% |=========================| 12 kB 00:00 ---> Package perl-DBI.i386 0:1.40-9 set to be updated --> Running transaction check Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: mysql i386 4.1.22-2.el4 base 3.1 M mysql-server i386 4.1.22-2.el4 base 9.9 M Installing for dependencies: perl-DBD-MySQL i386 2.9004-3.1.centos4 base 111 k perl-DBI i386 1.40-9 base 466 k Transaction Summary ============================================================================= Install 4 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 14 M Is this ok [y/N]: Y
Press Y and Enter and the packages will install
Downloading Packages: (1/4): perl-DBD-MySQL-2.9 100% |=========================| 111 kB 00:00 (2/4): perl-DBI-1.40-9.i3 100% |=========================| 466 kB 00:00 (3/4): mysql-4.1.22-2.el4 100% |=========================| 3.1 MB 00:01 (4/4): mysql-server-4.1.2 100% |=========================| 9.9 MB 00:04 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: perl-DBI ######################### [1/4] Installing: mysql ######################### [2/4] Installing: perl-DBD-MySQL ######################### [3/4] Installing: mysql-server ######################### [4/4] Installed: mysql.i386 0:4.1.22-2.el4 mysql-server.i386 0:4.1.22-2.el4 Dependency Installed: perl-DBD-MySQL.i386 0:2.9004-3.1.centos4 perl-DBI.i386 0:1.40-9 Complete!
The MYSQL Installation is now installed.
We just need to make MYSQL start when the server Starts up and all we need to do is create a system startup link, which is done with the following command.
[root@vps ~]# chkconfig --levels 235 mysqld on
Stopping and Starting MYSQL
If you have just installed MYSQL you will need to start MYSQL before you can changed the Root Password.
Otherwise the only times you really need to Stop/Start/Restart Mysql is if you have changed the config file.
Start:
[root@vps ~]# service mysqld start Starting MySQL: [ OK ]
Stop:
[root@vps ~]# service mysqld stop Stopping MySQL: [ OK ]
Restart:
[root@vps ~]# service mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
Status:
[root@vps ~]# service mysqld status mysqld (pid 7342) is running...
Changing Mysql Root Password
By default MYSQL's Root Password is left blank, allowing scripts to access MYSQL using Root username and no password. This is bad; it allows MYSQL to come under attack by malicious scripts attempting to exploit this so it is important to set a Root password, so scripts can only use a username and password given to them, which has restricted access.
To change the password, only requires a command. N.B change newrootpassword to your own password.
[root@vps ~]# mysqladmin -u root password newrootpassword
Command Line Backup and Restoration
To back up MYSQL by command line
mysqldump --add-drop-table -u [username] -p[password] [database] > [backup_file]
For Example
mysqldump --add-drop-table -u mysqlusername -pmysqlpassword mywebsite > mywebsite.sql
N.b: Note there is no space between the -p switch and the actual password.
You may also think about backing up the database called mysql, as it contains usernames/passwords and permissions for the databases.
To Restore a Backup
mysql -u [username] -p[password] [database] < [backup_file]
For Example
mysql -u mysqluser -pmysqlpassword mywebsite < mywebsite.sql
N.b: you may also need to restore the database called mysql if you have done a clean install od MYSQL.

