将root用户的密码设置为“p@ssw0rd”


[root@localhost mysql-5.0.56]# mysqladmin -u root password "p@ssw0rd"

[root@localhost mysql-5.0.56]# mysql -u mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.0.56-log Source distribution


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> quit

Bye


查看数据库列表信息


mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.01 sec)


mysql>


查看数据库中的数据表信息


mysql> use mysql;

Database changed

mysql> SHOW TABLES;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| func                      |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| proc                      |

| procs_priv                |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

17 rows in set (0.00 sec)


mysql>


每个数据表对应为三个文件


[root@localhost ~]# ls /usr/local/mysql/var/mysql | grep user

user.frm

user.MYD

user.MYI

[root@localhost ~]#


显示数据表的结构


mysql> use mysql;

Database changed

mysql> DESCRIBE user;

+-----------------------+-----------------------------------+------+-----+---------+-------+

| Field                 | Type                              | Null | Key | Default | Extra |

+-----------------------+-----------------------------------+------+-----+---------+-------+

| Host                  | char(60)                          | NO   | PRI |         |       |

| User                  | char(16)                          | NO   | PRI |         |       |

| Password              | char(41)                          | NO   |     |         |       |

| Select_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Insert_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Update_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Delete_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Create_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Drop_priv             | enum('N','Y')                     | NO   |     | N       |       |

| Reload_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Shutdown_priv         | enum('N','Y')                     | NO   |     | N       |       |

| Process_priv          | enum('N','Y')                     | NO   |     | N       |       |

| File_priv             | enum('N','Y')                     | NO   |     | N       |       |

| Grant_priv            | enum('N','Y')                     | NO   |     | N       |       |

| References_priv       | enum('N','Y')                     | NO   |     | N       |       |

| Index_priv            | enum('N','Y')                     | NO   |     | N       |       |

| Alter_priv            | enum('N','Y')                     | NO   |     | N       |       |

| Show_db_priv          | enum('N','Y')                     | NO   |     | N       |       |

| Super_priv            | enum('N','Y')                     | NO   |     | N       |       |

| Create_tmp_table_priv | enum('N','Y')                     | NO   |     | N       |       |

| Lock_tables_priv      | enum('N','Y')                     | NO   |     | N       |       |

| Execute_priv          | enum('N','Y')                     | NO   |     | N       |       |

| Repl_slave_priv       | enum('N','Y')                     | NO   |     | N       |       |

| Repl_client_priv      | enum('N','Y')                     | NO   |     | N       |       |

| Create_view_priv      | enum('N','Y')                     | NO   |     | N       |       |

| Show_view_priv        | enum('N','Y')                     | NO   |     | N       |       |

| Create_routine_priv   | enum('N','Y')                     | NO   |     | N       |       |

| Alter_routine_priv    | enum('N','Y')                     | NO   |     | N       |       |

| Create_user_priv      | enum('N','Y')                     | NO   |     | N       |       |

| ssl_type              | enum('','ANY','X509','SPECIFIED') | NO   |     |         |       |

| ssl_cipher            | blob                              | NO   |     | NULL    |       |

| x509_issuer           | blob                              | NO   |     | NULL    |       |

| x509_subject          | blob                              | NO   |     | NULL    |       |

| max_questions         | int(11) unsigned                  | NO   |     | 0       |       |

| max_updates           | int(11) unsigned                  | NO   |     | 0       |       |

| max_connections       | int(11) unsigned                  | NO   |     | 0       |       |

| max_user_connections  | int(11) unsigned                  | NO   |     | 0       |       |

+-----------------------+-----------------------------------+------+-----+---------+-------+

37 rows in set (0.01 sec)


mysql>


创建和删除新的数据库


mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.00 sec)


mysql> CREATE DATABASE auth;

Query OK, 1 row affected (0.00 sec)


mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| auth               |

| mysql              |

| test               |

+--------------------+

4 rows in set (0.00 sec)


mysql> DROP DATABASE auth;

Query OK, 0 rows affected (0.04 sec)


mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.00 sec)



创建和删除数据表


mysql> USE auth;

Database changed

mysql> SHOW TABLES;

Empty set (0.00 sec)


mysql> CREATE TABLE users (user_name CHAR(30) NOT NULL, user_passwd CHAR(20) NOT NULL DEFAULT '123456',PRIMARY KEY (user_name));

Query OK, 0 rows affected (0.02 sec)


mysql> SHOW TABLES;

+----------------+

| Tables_in_auth |

+----------------+

| users          |

+----------------+

1 row in set (0.01 sec)

mysql> USE auth;

Database changed

mysql> SHOW TABLES;

Empty set (0.00 sec)


mysql> CREATE TABLE users (user_name CHAR(30) NOT NULL, user_passwd CHAR(20) NOT NULL DEFAULT '123456',PRIMARY KEY (user_name));

Query OK, 0 rows affected (0.02 sec)


mysql> SHOW TABLES;

+----------------+

| Tables_in_auth |

+----------------+

| users          |

+----------------+

1 row in set (0.01 sec)


mysql> DROP TABLE auth.users;

Query OK, 0 rows affected (0.00 sec)


mysql> SHOW TABLES;

Empty set (0.00 sec)