如何使用mysql命令行 ?

来源:互联网 发布:通用数字滤波算法 编辑:程序博客网 时间:2024/06/05 16:00

开发中一直在使用navicat等客户端操作数据,好久没用命令行,都快忘记了,回忆一下, 使用命令行对mysql数据库操作


1, 登陆mysql 

指令 :  mysql -uroot

[root@VM_49_106_centos mysql]# mysql -urootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 11Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

2, 显示所有数据库

mysql>SHOW DATABASES;

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || sang               || test               |+--------------------+4 rows in set (0.00 sec)mysql> 

3, 新建数据库

mysql>CREATE DATABASE sang

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

4,使用数据库

mysql>USE 数据库名;

5, 新建表

mysql> create table study(    -> id int(11) not null,    -> userName varchar(32) not null,    -> passWord varchar(32) not null);Query OK, 0 rows affected (0.01 sec)mysql> 

6, 显示当前库中所有表

mysql>SHOW TABLES;

mysql> show tables;+----------------+| Tables_in_sang |+----------------+| study          |+----------------+1 row in set (0.00 sec)mysql> 

7, 修改表的名称

mysql> alter table study rename to dtudy_new;Query OK, 0 rows affected (0.00 sec)mysql> 

8, 显示表中字段信息

mysql> show columns from dtudy_new;+----------+-------------+------+-----+---------+-------+| Field    | Type        | Null | Key | Default | Extra |+----------+-------------+------+-----+---------+-------+| id       | int(11)     | NO   |     | NULL    |       || userName | varchar(32) | NO   |     | NULL    |       || passWord | varchar(32) | NO   |     | NULL    |       |+----------+-------------+------+-----+---------+-------+3 rows in set (0.00 sec)mysql> 

等等 ,还有非常多   http://jingyan.baidu.com/article/5bbb5a1b2b110213eba179d2.html


原创粉丝点击