NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Creating a Database With MySQL
Topic: Database   Posted:2003-12-29
Printer Friendly: Print

spacerspacer
Let's say we want to track our servers using a database instead of those nasty spreadsheets that many of us use. MySQL is a pretty simple and cheap way to get started. We are going to use a blank root password in these examples to ease typing, however, you should change the root password following our article here.

Let's create a database!

u-1@srv-1 mysqlart $ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 4.0.14-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database sysops;
Query OK, 1 row affected (0.00 sec)
mysql> quit
Bye
u-1@srv-1 mysqlart $ 

OK. We have a database. Now, let's enter a table and some fields. The easiest way to do this is to create a file first:

CREATE TABLE systemsdoc (
manu text NOT NULL,
model text NOT NULL,
addr text NOT NULL,
zip text NOT NULL,
phone text NOT NULL,
deploy_date text NOT NULL,
sernum text NOT NULL,
assetnum text NOT NULL,
machname text NOT NULL,
sysversion text NOT NULL,
UID int(11) NOT NULL default '0',
PRIMARY KEY  (UID)
) TYPE=MyISAM;

We can create the table and fields:

u-1@srv-1 mysqlart $ mysql sysops --user root < initialtable.sql

Here are some commands to show our database, table, and fields:

u-1@srv-1 mysqlart $ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.0.14-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+----------+
| Database |
+----------+
| mysql    |
| sysops   |
| test     |
+----------+
3 rows in set (0.00 sec)
mysql> 
mysql> connect sysops;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Connection id:    10
Current database: sysops
mysql> show tables;
+------------------+
| Tables_in_sysops |
+------------------+
| systemsdoc       |
+------------------+
1 row in set (0.00 sec)
mysql> 
mysql> describe systemsdoc;
+-------------+---------+------+-----+---------+-------+
| Field       | Type    | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| manu        | text    |      |     |         |       |
| model       | text    |      |     |         |       |
| addr        | text    |      |     |         |       |
| zip         | text    |      |     |         |       |
| phone       | text    |      |     |         |       |
| deploy_date | text    |      |     |         |       |
| sernum      | text    |      |     |         |       |
| assetnum    | text    |      |     |         |       |
| machname    | text    |      |     |         |       |
| sysversion  | text    |      |     |         |       |
| UID         | int(11) |      | PRI | 0       |       |
+-------------+---------+------+-----+---------+-------+
11 rows in set (0.00 sec)
mysql> quit
Bye
u-1@srv-1 mysqlart $





Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS