If you can see this check that

           prev section up prev page           

Administration of MySQL


Administration of MySQL

User:
Password:

Question 1: Start the server

Initially the MySQL server may not be running. Make sure it is running

Tests - not attempted
The MySQL server is running. [Details] UNTESTED
The MySQL server is set to restart on reboot. [Details] UNTESTED

Question 2: Secure the root account and create a user.

Many of the following commands should be executed from within a mysql client.

You can start a mysql session using the unix command mysql -u root -p (the password is blank initially - just press Enter when prompted for a password)

You may need to review commands to manage users. Recall:

SQL commands should be terminated with semi-colon.
Use FLUSH PRIVILEGES; after changing any of the system tables.
  • Protect the root account by supplying the password 'secure'.
  • Create a user scott with host localhost with password tiger.
Tests - not attempted
The root password has been set. [Details] UNTESTED
User scott is at localhost. [Details] UNTESTED
Scott can log in with password tiger. [Details] UNTESTED

Question 3: Create and protect databases and tables.

  • Create a database called number and a table called prime. The table prime should have exactly one field named i of type integer. You may use the following snippet to create the table:
    CREATE TABLE prime (i INTEGER);
    
  • Set the permissions so that scott can read the table but cannot add or change the contents.
Tests - not attempted
A database called number. [Details] UNTESTED
scott can read number.prime. [Details] UNTESTED
The user scott cannot insert values into the table. [Details] UNTESTED

Question 4: Create a database for scott.

Create a database called scott. Ensure that user scott@localhost has all privileges to database scott.
Tests - not attempted
scott owns a database [Details] UNTESTED

Question 5: Create a table as scott

Create and populate a table called beatles in the database scott as user scott. You may use the SQL given.
CREATE TABLE beatles(num INTEGER NOT NULL PRIMARY KEY, name VARCHAR(20));
INSERT INTO beatles VALUES (1,'John');
INSERT INTO beatles VALUES (2,'Paul');
INSERT INTO beatles VALUES (3,'George');
INSERT INTO beatles VALUES (4,'Ringo');
Tests - not attempted
There are four Beatles [Details] UNTESTED

Question 6: Accessing mysql over the web using perl

Start the web server.

The following perl program may be used to access the mysql database. Put the code in a file /var/www/cgi-bin/beatle.htm and test it by visiting the page http://host-1-19.linuxzoo.net/cgi-bin/beatle.htm - but substitue the actual address of your web server (you can find it from the "Server Administration" page).

You will need to make this file executable.

The sample shown does not include the functionality to delete beatles. You should do this yourself.

#!/usr/bin/perl
use strict;
use DBI;
use CGI qw(:standard);
import_names("Q");
print header;
my $dbh = DBI->connect("DBI:mysql:scott","scott","tiger")
  || print "Connection to mysql database failed: ". DBI->errstr;
print h1 "Beatles";
if ($Q::d){
  print "You asked to delete: $Q::d";
}
my $sth = $dbh->prepare("select * from beatles")
  || print "The statement could not be prepared." . DBI->errstr;
$sth->execute
  || print "The statement could not be executed." . DBI->errstr;
while (my ($number,$name) = $sth->fetchrow_array){
  print p "$number, $name " .
         a({-href=>"?d=$number"},"Delete this Beatle");
}


Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
Caine 13.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Registry | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2024 Edinburgh Napier University