mysql的安裝和使用

來源:互聯網
上載者:User

http://wenku.baidu.com/view/3f7319a4f524ccbff1218468.html


1. 安裝

http://www.cnblogs.com/276815076/archive/2012/04/01/2428364.html

安裝包

sudo apt-get install mysql-server

設定root密碼

mysqladmin -u root password 'abc123' -p

2. configure the mysql to accept connection from outside.
    In /etc/mysql/my.cnf change this:
        bind-address            = 127.0.0.1
    to
        bind-address            = 0.0.0.0

3. configure mysql to accept root connection from remote host
grant all privileges on *.* to 'root'@'%' identified by 'passwd' with grant option;

這個方法轉自http://www.cnblogs.com/wliang22/archive/2009/11/13/1602423.html

4. 建立使用者

create user abc;

2. 建立/選擇資料庫

create database dev;

show databases;

use dev;

drop database dev;

刪除資料庫。

3. 顯示/建立表

show tables;

create table pet(name varchar(20), owner varchar(20), species varchar(20), sex char(1), birth date, death date);

describe pet;

+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name    | varchar(20) | YES  |     | NULL    |       |
| owner   | varchar(20) | YES  |     | NULL    |       |
| species | varchar(20) | YES  |     | NULL    |       |
| sex     | char(1)     | YES  |     | NULL    |       |
| birth   | date        | YES  |     | NULL    |       |
| death   | date        | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+

drop table pet;

刪除表

4. 從檔案中匯入表的資料

5. 資料的輸入和讀取

insert into pet values('Puffball', 'Diane', 'hamster', 'f', '1993-02-01', NULL);

select * from pet;

select 的格式是

select what_to_select

from which_table

where conditions_to_satisfy

select distinct owner from pet;

不顯示重複的。

select name,birth from pet order by birth;

排序

6. 刪除表的內容

delete from pet;

7. 更新表的記錄

update pet set death='3098-09-08' where name='Puffball';

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.