|
Databases
Users
First Blush
MySQL installation will setup two databases: mysql & test . test
is an empty database with unrestricted access - it can be deleted. mysql is
a required database and is only accessible to root user, it contains
information for all databases, users, and the restriction/security parameters.
The show databases command (example shown below) is a good way to
see the database manifest. The special mysql database contains
critial information that dictates user privledges and allows administration
of custom databases.
Default MySQL installation will setup a special root user and a
default user mode for when no user is specified. All users and their
respective privledges are maintained in the user table of the
mysql database (example user table shown below).
$ mysql -u root
mysql> show databases;
+-------------+
| Database |
+-------------+
| mysql |
| test |
+-------------+
mysql> use mysql
mysql> show tables;
+-----------------+
| Tables_in_mysql |
+-----------------+
| columns_priv |
| db |
| func |
| host |
| tables_priv |
| user |
+-----------------+
mysql> select * from user;
+--------------------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv |
+--------------------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
| localhost | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
| jabber.zaptech.com | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
| localhost | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| jabber.zaptech.com | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
+--------------------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
More details about how this table controls access to databases available at 4.2.9 Access Control, Stage 1: Connection Verification
mysql> select * from db;
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+
| Host | Db | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv |
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+
| % | test | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y |
| % | test\_% | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y |
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+
mysql> quit
Ok Now What -
creating/dropping databases, creating/dropping tables,
adding/dropping table fields
$ mysql -u root mysql> show databases; +-------------+ | Database | +-------------+ | mysql | | test | +-------------+ mysql> create database foo; mysql> show databases; +-------------+ | Database | +-------------+ | mysql | | foo | | test | +-------------+ mysql> use foo mysql> drop database foo; +-------------+ | Database | +-------------+ | mysql | | test | +-------------+ mysql> quitNote: sometimes an empty directory in var/lib/mysql remains for a dropped database. As root, check that the [database]/ directory is empty, then rm -rf [database] |
$ mysql -u root mysql> show databases; +-------------+ | Database | +-------------+ | mysql | | test | +-------------+ mysql> create database foo; mysql> use foo mysql> create table kipple ( name varchar(40) null); mysql> show tables; +---------------+ | Tables_in_mag | +---------------+ | kipple | +---------------+ mysql> show fields from kipple; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | name | varchar(40) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ mysql> drop table kipple; mysql> show tables; Empty set mysql> quit |
$ mysql -u root mysql> use foo mysql> show tables; Empty set mysql> create table kipple ( name varchar(40) null); mysql> show fields from kipple; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | name | varchar(40) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ mysql> alter table kipple add column description text null after name; mysql> show fields from kipple; +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | name | varchar(40) | YES | | NULL | | | description | text | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+ mysql> alter table kipple drop column description; mysql> show fields from kipple; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | name | varchar(40) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ mysql> drop table kipple; mysql> show tables; Empty set mysql> quit |