常用mysql語句

來源:互聯網
上載者:User

標籤:mysql語句

二、常用SQL語句

庫 -- >表 -- >行 -- >欄位

■庫操作

___________________________________________________________


mysql> show databases;       #查看本地庫+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.08 sec)
mysql> use mysql            #切換庫Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed
mysql> select database();     #查看當前庫+------------+| database() |+------------+| mysql      |+------------+1 row in set (0.00 sec)
mysql> select version();        #查看當前資料庫版本+-----------+| version() |+-----------+| 5.6.28    |+-----------+1 row in set (0.00 sec)
mysql> create database szk;          #建立一個szk庫Query OK, 1 row affected (0.02 sec)
mysql> drop database szk;            #刪除庫Query OK, 0 rows affected (0.00 sec)

■表操作

___________________________________________________________

mysql> show tables;                 #查看當前庫中的表+---------------------------+| Tables_in_mysql           |+---------------------------+| columns_priv              || db                        || event                     || func                      || general_log               || help_category             || help_keyword              |
mysql> desc user;               #查看當前表的欄位+------------------------+-----------------------------------+------+-----+-----------------------+-------+| Field                  | Type                              | Null | Key | Default               | Extra |+------------------------+-----------------------------------+------+-----+-----------------------+-------+
mysql>  insert into tb1 values(1, ‘szk‘);      #插入語句1Query OK, 1 row affected (0.01 sec)mysql>  select * from tb1;       #查看錶中語句+------+------+| id   | name |+------+------+|    1 | szk  |+------+------+1 row in set (0.00 sec)
mysql> truncate table tb1;         #清空這個表Query OK, 0 rows affected (0.00 sec)mysql> drop table tb1;               #刪除這個表Query OK, 0 rows affected (0.00 sec)mysql> create table tb1 (`id` int(4), `name` char(40)) ENGINE=MyISAM DEFAULT CHARSet=gbk;    #建立一個表,表名為tb1,並且有倆語句,編碼為gbk Query OK, 0 rows affected (0.02 sec)
mysql> desc tb1;     #查看當前表中欄位+-------+----------+------+-----+---------+-------+| Field | Type     | Null | Key | Default | Extra |+-------+----------+------+-----+---------+-------+| id    | int(4)   | YES  |     | NULL    |       || name  | char(40) | YES  |     | NULL    |       |+-------+----------+------+-----+---------+-------+2 rows in set (0.00 sec)

■許可權操作

___________________________________________________________

[[email protected] ~]# mysqladmin -uroot password ‘111qqq...‘    #給root使用者佈建密碼文法:CREATE USER ‘username‘@‘host‘ IDENTIFIED BY ‘password‘;mysql> create user [email protected] identified by ‘szk5043‘;      #建立一個mysql登入使用者,通過identified設定密碼,並且限制使用者只能從指定的主機登入mysql> Drop user szk5043;     #刪除使用者文法:grant 許可權1,許可權2,...許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者地址 identified by ‘串連口令‘;select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權mysql>grant all privileges on *.* to [email protected] identified by ‘szk5043‘;  給szk5043分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為szk5043mysql>flush privileges;   #重新整理系統許可權表

■查看操作

___________________________________________________________

mysql> show variables;         #查看進程mysql> show status;              #查看狀態mysql> show status like ‘%running‘;      #查看單個對象狀態+-----------------+-------+| Variable_name   | Value |+-----------------+-------+| Slave_running   | OFF   || Threads_running | 1     |+-----------------+-------+2 rows in set (0.00 sec)mysql> repair table discuz.pre_forum_port;         #修複表+-----------------------+--------+----------+---------------------------------------------+| Table                 | Op     | Msg_type | Msg_text                                    |+-----------------------+--------+----------+---------------------------------------------+| discuz.pre_forum_port | repair | Error    | Table ‘discuz.pre_forum_port‘ doesn‘t exist || discuz.pre_forum_port | repair | status   | Operation failed                            |+-----------------------+--------+----------+---------------------------------------------+


本文出自 “撫琴煮酒” 部落格,請務必保留此出處http://szk5043.blog.51cto.com/8456440/1762961

常用mysql語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.