Database Administration
Download
Report
Transcript Database Administration
Introduction to
PHP and MySQL
Kirkwood Center for
Continuing Education
By Fred McClurg, [email protected]
Copyright © 2016, Fred McClurg, All Rights Reserved.
Chapter Nine
Database Administration
http://cecert.kirkwood.edu/~fmcclurg/courses/php/
slides/chapter09f.administration.ppt
2
Backing Up MySQL Data (Copy Method)
Database Copy Procedure
1. Shut down the MySQL service
2. Copy data files to backup location
http://localhost/phpmyadmin/
On Windows:
C:\Program Files\MySQL\MySQL
Server 5.1\data\database_name
C:\xampp\mysql\data
On Unix:
/var/lib/mysql
3
Restoring MySQL Data (Copy Method)
Restoring Database Procedure:
1. All files must be replaced in the
same directory from which they
were backed up.
2. Restart database service
4
Copy Method Advantages/Disadvantages
Advantages:
1. Fast
2. Easy
Disadvantages
1. Not recommended for moving or
upgrading databases
2. All or nothing data restoration
5
mysqldump Backup (Preferred Method)
Creating mysqldump Backups
Description: The SQL commands used to
create the tables and the data can be
redirected to a file. That file can then be used
to rebuild the database.
Syntax:
mysqldump –u user –p db_name
mysqldump –u user –p db_name
table_name
6
Creating mysqldump Backups
Examples:
Backup one database:
mysqldump –u root –p
notedb >
notedb_backup.sql
Backup one database table:
mysqldump –u root –p
notedb notecard >
notecard_backup.sql
7
Creating mysqldump Backup (cont.)
Examples:
Backup all databases:
mysqldump –u root –p
–-all-databases > full_backup.sql
Backup Schema w/o Data:
mysqldump –u root –p
-–not-data > schema_only.sql
Backup Data Only w/o Schema:
mysqldump –u root –p
-–no-create-info > data_only.sql
8
mysqldump Advantages/Disadvantages
Advantages:
1. SQL generated can be used to migrate
database to a new version or architecture
2. Can be used for a partial backup/restore
3. Scriptable
Disadvantages
1. Not point and click
Note: Similar capability is available via
phpmyadmin
9
Restoring mysqldump Backups
Restore databases created with
--all-databases:
mysql –u root –p
< full_backup.sql
Restore only one database:
mysql –u root –p -D notedb
< notedb_backup.sql
10
Working with CSV Data in MySQL
Exporting Database in CSV Format
Create separate files for each table in database:
mysqldump –u root –p
--no-create-info
--tab=csvDir
--fields-terminated-by=',' notedb
Importing CSV into Database:
mysqlimport –u root –p
--fields-terminated-by=',' notedb
notecard.csv
Note: The filename prefix determines the table name
11
For more MySQL Information
General Documentation:
http://dev.mysql.com/doc/
MySQL 5.5 Reference Manual:
http://dev.mysql.com/doc/refman/5.5/en/
12
to be continued ...
http://cecert.kirkwood.edu/~fmcclurg/courses/php/
slides/chapter10.phpAndMysql.ppt
13