Mysql: Difference between revisions

From Hackepedia
Jump to navigationJump to search
No edit summary
 
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  Enter password:  
  Enter password:  
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Welcome to the MySQL monitor.  Commands end with ; or \g.
If you don't yet have a mysql root user password:
mysql> SET PASSWORD FOR root@localhost=PASSWORD('SeCreT');


What databases exist:
What databases exist:
Line 23: Line 27:


Create a basic table:
Create a basic table:
mysql> CREATE TABLE volunteers (firstname VARCHAR(20), lastname VARCHAR(20), callsign   VARCHAR(6), shirtsize CHAR(2), years CHAR(2), location VARCHAR(20) );
  mysql> CREATE TABLE volunteers (
  firstname VARCHAR(20),
  lastname VARCHAR(20),
  callsign VARCHAR(6),
  shirtsize CHAR(2),
  years CHAR(2),
  location VARCHAR(20)
  );
  Query OK, 0 rows affected (0.01 sec)
  Query OK, 0 rows affected (0.01 sec)


Line 30: Line 41:


Now to load some data:
Now to load some data:
  mysql> INSERT INTO volunteers VALUES ('Diane','Bruce','ve3db','l','2','room 412');  
  mysql> INSERT INTO volunteers VALUES ('Diane','Bruce','va3db','l','2','room 412');  


Edit the data, as ve3sql is now an extra large t-shirt:
Edit the data, as ve3sql is now an extra large t-shirt:

Latest revision as of 09:56, 13 June 2006

To login to mysql from the shell as user root of mysql:

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.

If you don't yet have a mysql root user password:

mysql> SET PASSWORD FOR root@localhost=PASSWORD('SeCreT');

What databases exist:

mysql> show databases;

To create a database:

mysql> create database bsdcan;    
Query OK, 1 row affected (0.00 sec)

Create a user to with a grant of "all" where the username will be bsdadmin and the client machine is localhost:

mysql> grant all on bsdcan.* to 'bsdadmin'@'localhost';
Query OK, 0 rows affected (0.09 sec)

Now let's use our new database:

mysql> use bsdcan;

and see what tables exist:

mysql> show tables;

Create a basic table:

 mysql> CREATE TABLE volunteers (
 firstname VARCHAR(20),
 lastname VARCHAR(20),
 callsign VARCHAR(6),
 shirtsize CHAR(2),
 years CHAR(2),
 location VARCHAR(20)
 );
Query OK, 0 rows affected (0.01 sec)

Let's take a look at our new table:

mysql> describe volunteers;

Now to load some data:

mysql> INSERT INTO volunteers VALUES ('Diane','Bruce','va3db','l','2','room 412'); 

Edit the data, as ve3sql is now an extra large t-shirt:

mysql> update volunteers set shirtsize='xl' where callsign='ve3sql';

what do we have in the table now?

mysql> SELECT * FROM volunteers;

We accidently added a record with a volunteer we want to delete:

mysql> delete from volunteers where callsign='ve3sql';