码迷,mamicode.com
首页 > 数据库 > 详细

MySQL初识

时间:2015-09-30 18:19:56      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:oracle   计算机   数据库   创始人   安全性   

数据库(DataBase):是指长期保存在计算机的存储设备上,按照一定规则组织起来,可以被各种用户或应用共享的数据集合;


DBMS:数据库操作系统:一种操作和管理数据库的大型软件,用于建立、使用和维护数据库,对数据库进行统一管理和控制,以保证数据库的安全性和完整性;


DDL:定义语言

DML:操作语言

DCL:控制语言


MYSQL 由三个瑞典人于20世纪90年代开发的一个关系型数据库 MY是创始人之一MICHAEL WIDENIUS女儿MY的名字

常用的数据库:Oracle , DB2 , SQL Server , PostgreSQL 


[root@Freedom1991 /]# mysql

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

Your MySQL connection id is 1

Server version: 5.6.25 MySQL Community Server (GPL)


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


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


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


mysql> 


[root@Freedom1991 /]# netstat -tanp      监听在3306端口

tcp     0      0 :::3306         :::*          LISTEN      1989/mysqld   



[root@Freedom1991 ~]# mysql -u root -p   本机登录

Enter password: 

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

Your MySQL connection id is 4

Server version: 5.6.25 MySQL Community Server (GPL)


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


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


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


mysql> 

可以在用户家目录下,编写一个隐藏脚本,实现不用输入密码直接登录;

[root@Freedom1991 ~]# ls -a

.                .bash_history  .cache   .dmrc      .gconfd          .gnupg           .ICEauthority       .kde      .my.cnf         .pulse-cookie  .targetcli  .viminfo              公共的  文档

..               .bash_logout   .config  .elinks    .gnome2          .gstreamer-0.10  .imsettings.log     linux     .mysql_history  .rnd           .tcshrc     .Xauthority           模板    下载

.abrt            .bash_profile  .cshrc   .esd_auth  .gnome2_private  .gtk-bookmarks   install.log         .local    .nautilus       .ssh           test        .xsession-errors      视频    音乐

anaconda-ks.cfg  .bashrc        .dbus    .gconf     .gnote           .gvfs            install.log.syslog  .mozilla  .pulse          .subversion    test1       .xsession-errors.old  图片    桌面

[root@Freedom1991 ~]# cat .my.cnf

[client]

user=‘root‘

password=‘redhat‘

host=‘localhost‘

[root@Freedom1991 ~]# 


[root@Freedom1991 ~]# mysqladmin -uroot -predhat password mysql   将原密码redhat改为mysql

Warning: Using a password on the command line interface can be insecure.



mysql> help  显示帮助信息;


For information about MySQL products and services, visit:

   http://www.mysql.com/

For developer information, including the MySQL Reference Manual, visit:

   http://dev.mysql.com/

To buy MySQL Enterprise support, training, or other products, visit:

   https://shop.mysql.com/


List of all MySQL commands:

Note that all text commands must be first on line and end with ‘;‘

?         (\?) Synonym for `help‘.

clear     (\c) Clear the current input statement.

connect   (\r) Reconnect to the server. Optional arguments are db and host.

delimiter (\d) Set statement delimiter.

edit      (\e) Edit command with $EDITOR.

ego       (\G) Send command to mysql server, display result vertically.

exit      (\q) Exit mysql. Same as quit.

go        (\g) Send command to mysql server.

help      (\h) Display this help.

nopager   (\n) Disable pager, print to stdout.

notee     (\t) Don‘t write into outfile.

pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.

print     (\p) Print current command.

prompt    (\R) Change your mysql prompt.

quit      (\q) Quit mysql.

rehash    (\#) Rebuild completion hash.

source    (\.) Execute an SQL script file. Takes a file name as an argument.

status    (\s) Get status information from the server.

system    (\!) Execute a system shell command.

tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.

use       (\u) Use another database. Takes database name as argument.

charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.

warnings  (\W) Show warnings after every statement.

nowarning (\w) Don‘t show warnings after every statement.


For server side help, type ‘help contents‘


mysql> show privileges;    显示权限信息

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

| Privilege               | Context                               | Comment                                               |

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

| Alter                   | Tables                                | To alter the table                                    |

| Alter routine           | Functions,Procedures                  | To alter or drop stored functions/procedures          |

| Create                  | Databases,Tables,Indexes              | To create new databases and tables                    |

| Create routine          | Databases                             | To use CREATE FUNCTION/PROCEDURE                      |

| Create temporary tables | Databases                             | To use CREATE TEMPORARY TABLE                         |

| Create view             | Tables                                | To create new views                                   |

| Create user             | Server Admin                          | To create new users                                   |

| Delete                  | Tables                                | To delete existing rows                               |

| Drop                    | Databases,Tables                      | To drop databases, tables, and views                  |

| Event                   | Server Admin                          | To create, alter, drop and execute events             |

| Execute                 | Functions,Procedures                  | To execute stored routines                            |

| File                    | File access on server                 | To read and write files on the server                 |

| Grant option            | Databases,Tables,Functions,Procedures | To give to other users those privileges you possess   |

| Index                   | Tables                                | To create or drop indexes                             |

| Insert                  | Tables                                | To insert data into tables                            |

| Lock tables             | Databases                             | To use LOCK TABLES (together with SELECT privilege)   |

| Process                 | Server Admin                          | To view the plain text of currently executing queries |

| Proxy                   | Server Admin                          | To make proxy user possible                           |

| References              | Databases,Tables                      | To have references on tables                          |

| Reload                  | Server Admin                          | To reload or refresh tables, logs and privileges      |

| Replication client      | Server Admin                          | To ask where the slave or master servers are          |

| Replication slave       | Server Admin                          | To read binary log events from the master             |

| Select                  | Tables                                | To retrieve rows from table                           |

| Show databases          | Server Admin                          | To see all databases with SHOW DATABASES              |

| Show view               | Tables                                | To see views with SHOW CREATE VIEW                    |

| Shutdown                | Server Admin                          | To shut down the server                               |

| Super                   | Server Admin                          | To use KILL thread, SET GLOBAL, CHANGE MASTER, etc.   |

| Trigger                 | Tables                                | To use triggers                                       |

| Create tablespace       | Server Admin                          | To create/alter/drop tablespaces                      |

| Update                  | Tables                                | To update existing rows                               |

| Usage                   | Server Admin                          | No privileges - allow connect only                    |

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

31 rows in set (0.00 sec)


[root@Freedom1991 ~]# mysqladmin -u root -h localhost -p processlist  查看活动线程

Enter password: 

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

| Id | User | Host      | db | Command | Time | State | Info             |

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

| 12 | root | localhost |    | Query   | 0    | init  | show processlist |

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

[root@Freedom1991 ~]# 


[root@Freedom1991 ~]# mysqladmin -u root status  显示服务器运行状态

Uptime: 22965  Threads: 1  Questions: 28  Slow queries: 0  Opens: 14  Flush tables: 1  Open tables: 7  Queries per second avg: 0.001

[root@Freedom1991 ~]# mysqladmin -u root -p status

Enter password: 

Uptime: 22979  Threads: 1  Questions: 30  Slow queries: 0  Opens: 14  Flush tables: 1  Open tables: 7  Queries per second avg: 0.001



[root@Freedom1991 ~]# mysqladmin -uroot -p shutdown   关闭mysql服务器

Enter password: 



[root@Freedom1991 ~]# mysqlshow   显示本地数据库服务器上的数据库

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

|     Databases      |

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

| information_schema |

| mydb               |

| mysql              |

| students           |

| test               |

| testdb             |

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


显示数据库中的表信息

[root@Freedom1991 ~]# mysqlshow mysql

Database: mysql

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

|          Tables           |

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

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| servers                   |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

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


[root@Freedom1991 ~]# mysqlshow mysql func   显示表中的字段信息

Database: mysql  Table: func

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

| Field | Type                         | Collation       | Null | Key | Default | Extra | Privileges                      | Comment |

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

| name  | char(64)                     | utf8_bin        | NO   | PRI |         |       | select,insert,update,references |         |

| ret   | tinyint(1)                   |                 | NO   |     | 0       |       | select,insert,update,references |         |

| dl    | char(128)                    | utf8_bin        | NO   |     |         |       | select,insert,update,references |         |

| type  | enum(‘function‘,‘aggregate‘) | utf8_general_ci | NO   |     |         |       | select,insert,update,references |         |

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


MySQL初识

标签:oracle   计算机   数据库   创始人   安全性   

原文地址:http://freedom1991.blog.51cto.com/10752428/1699547

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!